views:

373

answers:

1

Dear all.

I am creating WCF service that will download & upload xml files. When trying to download a file to a client, it gives me the following error:

*"The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (multipart/related; type=\"application/xop+xml\"). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: ' \n \n \nIIS 7.0 Detailed Error - 500.19 - Internal Server Error \n \nmargin-top:0px; \n border-top:1px solid #EDEDED;border-left:1px solid #EDEDED;border-right:1px solid #969696; \n border-bottom:1px solid #969696;background:#E7ECF0;font-weight:bold;'."

I am using basicHTTPBinding as my binding protocol. My webservice is currently hosted on my own pc on IIS7.0 under Vista Home Premium. The download code in the service I am using is the following:

 public Stream Download( string path )
    {
        try
        {
            using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {

                return stream;
            }
        }
        catch (Exception ex)
        {
            string error = ex.Message;

            return null;
        }
    }

The code on my client that is supposed to download the file is the following, using just an ordinary test file:

 System.IO.FileStream fs;
        try
        {
            fs = (System.IO.FileStream)client.Download(@"C:\UploadedFiles\Test.txt");
            byte[] arr = new byte[fs.Length];
            int read;
            do
            {
                read = fs.Read(arr, 0, arr.Length);

            } while (read != arr.Length);

            Console.WriteLine(ASCIIEncoding.ASCII.GetString(arr));
            Console.ReadLine();
        }
        catch (Exception Ex)
        {
            string error = Ex.Message;
            string inner = Ex.InnerException.ToString(); ;
            Console.WriteLine("Exception: {0}/nInner Exception: {1}",error,inner);
            Console.ReadLine();
        }

Someone please help me out, I don't understand what is wrong?

If you need more data to help me resolve, also let me know.

Thanks a lot, T

+1  A: 

The "Internal Server error" should tip you off that it's the server that is having a problem "serving" up the service. Your code doesn't even have a chance to execute so it's not the culprit. You need to make sure IIS is configured correctly.

Start by verifying that your Authentication mode is correct. If you're using impersonation, you will also need to have that activated. If you've been using the ASP.NET Development Server (the one that automatically starts up on your machine when you start debugging), then you should know that it is rather lax when it comes to your configuration. IIS is picky.

Pretty much all changes that you make in IIS can also be reflected through your web.config, so remember the tweaks you did to IIS and reflect these changes in your web.config. This ensures that the problems will not crop back up again (say, after another build).

If your project is a "WCF Service Application", then you should be able to see a more detailed error message by logging into the server that you're hosting the service on and viewing the .svc file from the browser.

James Jones
Could you help me configure it? I have not much experience doing this. I have never run a WCF Service on IIS7.0. Maybe you know of a good tutorial to help me configure it?
Tony
going to: http://localhost/xmlLoadService/login.aspx?ReturnUrl=/xmlLoadService/Service.svcI get this error: HTTP Error 401.2 - UnauthorizedYou are not authorized to view this page due to invalid authentication headers.
Tony
I just edited and added more info. Log into your server and view the .svc file from your browser and you will get a detailed error message. If the error message still has you confused, simply type it into Google and you will likely quickly find an answer. Keep repeating those steps until you have it working. :)
James Jones
This is what it says in my web.config file under Authentication mode:<authentication mode="Forms" /> <authorization> <allow roles="./Administrators" /> <allow users="Hostname/User" /> </authorization>
Tony
Thanks for that james
Tony
Ah, it looks like you're not hosting a true WCF service. A .aspx file is indicative of the old style ASP.NET Web Service.
James Jones
Since you're using Forms authentication, make sure that it's enabled in the IIS of the hosting server.
James Jones