我的 .NET 4.0 Web 应用程序项目中有一个 WCF 端点。使用 VS2010 WCF 测试客户端,我可以正确连接到服务。但是,当我使用该服务时,会收到一条通用错误消息:
内容类型 text/html;响应消息的 charset=UTF-8 与绑定的内容类型不匹配 (text/xml; charset=utf-8)。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节是:
当我查看 IIS Express 上的请求时,我得到以下信息:
请求开始:POST http://machinename:port/Services/Services.svc
请求开始:GET http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1
请求结束:“http://machinename:port/Services/Services.svc”,HTTP 状态为 302.0
请求结束:“http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1”,HTTP 状态为 302.0
请求结束:“http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1”,HTTP 状态为 200.0
因此,在发布到服务之后,它似乎被重定向到服务的标准网页。然而,当我删除:
<authentication mode="Forms">
<forms cookieless="AutoDetect" loginUrl="~/Security/LoginClient.aspx" name="FORMAUTH" />
从 web.config 它可以工作。任何想法发生了什么?我试图从身份验证中删除服务所在的文件夹(http://stackoverflow.com/questions/5593720/authentication-mode-forms-causing-errors-in-wcf-end-point),但问题仍然存在。
虽然当我通过 IIS Express 7.5 运行它时使用 Visual Studio Development Server (Cassini) 有效,但无论是否进行身份验证,都会发生相同的错误。