0

我的 .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

请求开始: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),但问题仍然存在。

虽然当我通过 IIS Express 7.5 运行它时使用 Visual Studio Development Server (Cassini) 有效,但无论是否进行身份验证,都会发生相同的错误。

4

2 回答 2

2

您必须为您的 web 服务提供授权,以便在 web.config 中匿名联系:

<location path="MyWebServices">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

这假设您将所有服务保存在MyWebServices相对于应用程序根目录的文件夹中。您必须允许*,否则它将强制登录以进行访问。

于 2011-06-06T12:56:40.200 回答
0

一旦我在服务地址中使用机器名而不是 localhost,我就会遇到同样的问题。我确实尝试使用“baseAddressPrefixFilters”但没有成功。

<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://XLSiteSampleD.aginsurance.intranet/PIXLSiteSample" />
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

我认为该选项可能是在 web.config 中使用服务上的相关属性启用 aspNetCompatibility:[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 但也不是诀窍:(

它仅适用于http://localhost/VirtualSite/MyService.svc这样没有域且没有 baseAddressPrefixFilters 的地址!

五。

于 2011-06-06T12:53:56.970 回答