我的 .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< /p>
请求已开始:GET http://machinename:port/Services/Services.svc? AspxAutoDectectCookieSupport=1
请求已开始:GET http:// /machinename:port/(X(1)A(LKwosYYszAEkAAAAMDE2YzlmNWItNTZIOS00ZDY1LTgzOTAtNDIxNDgyOWZIYWViJ86TX46muUQoL_psmkZK2rgWbO41))/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),但问题仍然存在。
虽然使用 Visual Studio 开发服务器 (Cassini) 可以正常工作,但当我通过 IIS Express 7.5 运行它时,无论是否进行身份验证,都会出现相同的错误。
I have a WCF end point inside my .NET 4.0 Web Application project. Using the VS2010 WCF Test Client, I can connect to the service correctly. However when I go to use the service I get a generic error message:
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:
When I looked at the requests on IIS Express I got the following:
Request started: POST http://machinename:port/Services/Services.svc
Request started: GET http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1
Request started: GET http://machinename:port/(X(1)A(LKwosYYszAEkAAAAMDE2YzlmNWItNTZIOS00ZDY1LTgzOTAtNDIxNDgyOWZIYWViJ86TX46muUQoL_psmkZK2rgWbO41))/Services/Services.svc?AspxAutoDectectCookieSupport=1
Request ended: "http://machinename:port/Services/Services.svc" with HTTP status 302.0
Request ended: "http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1" with HTTP status 302.0
Request ended: "http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1" with HTTP status 200.0
So it seems like after POSTing to the service it is getting redirected to the standard web page for the service. Yet when I remove:
<authentication mode="Forms">
<forms cookieless="AutoDetect" loginUrl="~/Security/LoginClient.aspx" name="FORMAUTH" />
from the web.config it works. Any ideas what is happening? I have tried to remove the folder the service is in from authentication (http://stackoverflow.com/questions/5593720/authentication-mode-forms-causing-errors-in-wcf-end-point) but the issue still remains.
While this works using the Visual Studio Development Server (Cassini) when I run it through IIS Express 7.5 the same error occurs with or without authentication.
发布评论
评论(2)
当我在服务地址中使用机器名而不是 localhost 时,我就会遇到同样的问题。我确实尝试使用“baseAddressPrefixFilters”但没有成功。
我认为该选项可能是在 web.config 中启用 aspNetCompatibility
与服务上的相关属性:
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
但这也不是窍门:(
它只适用于像 http://localhost/VirtualSite/MyService.svc 这样的地址 没有域并且没有 baseAddressPrefixFilters
V.
I am experiencing the same issue as soon as I use the machinename instead of localhost in the service address. I did try to use a "baseAddressPrefixFilters" but without success.
I thought that option could have been to enable the aspNetCompatibility in the web.config
with the related attribute on the service :
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
But is does not the trick either :(
It only works with an address like http://localhost/VirtualSite/MyService.svc without a domain and without the baseAddressPrefixFilters !
V.
您必须在 web.config 中为要匿名联系的 Web 服务提供授权:
这假设您将所有服务保存在相对于应用程序根目录的名为
MyWebServices
的文件夹中。您必须允许*
否则它将强制登录才能访问。You have to provide authorization for your web services to be contacted anonymously in your web.config:
This assumes that you keep all of your services in a folder called
MyWebServices
relative to the root of the application. You have to allow*
or it will force a login for access.