简体   繁体   English

WCf服务文件下载

[英]WCf service file download

I am creating WCF service that will download & upload xml files. 我正在创建WCF服务,该服务将下载和上传xml文件。 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: ' \\nhttp://www.w3.org/1999/xhtml\\"> \\n \\nIIS 7.0 Detailed Error - 500.19 - Internal Server Error \\n \\n “响应消息的内容类型text / html; charset = utf-8与绑定的内容类型不匹配(multipart / related; type = \\“ application / xop + xml \\”)。如果使用自定义编码器,确保正确实现IsContentTypeSupported方法。响应的前1024个字节为:'\\ nhttp://www.w3.org/1999/xhtml \\“> \\ n \\ nIIS 7.0详细错误-500.19-内部服务器错误\\ n \\ n

I am using basicHTTPBinding as my binding protocol. 我正在使用basicHTTPBinding作为绑定协议。 My webservice is currently hosted on my own pc on IIS7.0 under Vista Home Premium. 我的Web服务当前托管在Vista Home Premium下IIS7.0上我自己的PC上。 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 非常感谢,T

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. 您需要确保IIS配置正确。

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. 如果您一直在使用ASP.NET开发服务器(在开始调试时会自动在计算机上启动的服务器),那么您应该知道它在配置方面比较宽松。 IIS is picky. IIS很挑剔。

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. 您在IIS中所做的几乎所有更改也可以通过web.config反映出来,因此请记住您对IIS所做的调整,并将这些更改反映在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. 如果您的项目是“ WCF服务应用程序”,那么应该登录到承载该服务的服务器,并从浏览器中查看.svc文件,从而可以看到更详细的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM