2011-04-08 58 views
0

我的.NET 4.0 Web应用程序项目中有一个WCF端点。使用VS2010 WCF测试客户端,我可以正确连接到该服务。但是,当我去使用该服务时,我收到一条通用错误消息:身份验证模式=“窗体”导致在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

Reque st结束:HTTP状态为“http:// machinename:port/Services/Services.svc”302.0

请求以HTTP结尾:“http:// machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport = 1”状态302.0

请求结束: “HTTP://机器:端口/服务/ 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开发服务器(Cassini),但在使用或不使用身份验证时会发生相同的错误。

+0

您好!面对同样的问题。你找到解决方案吗? – user1147981 2015-12-11 16:43:59

回答

0

我在服务地址中使用machinename而不是localhost时遇到同样的问题。我曾尝试使用“baseAddressPrefixFilters”,但没有成功。

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

我认为选择可能已经使aspNetCompatibility在web.config 与服务相关的属性: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed) 但就是不招要么:(

只与像http://localhost/VirtualSite/MyService.svc地址作品,未经域和没有baseAddressPrefixFilters!

五。

2

你必须提供授权将在你的web.config匿名联系了Web服务:

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

这是假设你把你所有的服务的叫MyWebServices相对的根文件夹中应用。您必须允许*,否则它将强制登录进行访问。

+0

这就是我以为是这就是为什么我在这里问它[http://stackoverflow.com/questions/5593720/authentication-mode-forms-causing-errors-in-wcf-end-point](http: //stackoverflow.com/questions/5593720/authentication-mode-forms-causing-errors-in-wcf-end-point)但尝试过,它仍然重定向我 – SmudgerDan 2011-06-09 15:02:46

+0

不工作。如果在WCF中引发任何问题,它仍然会重定向到默认的loginUrl。我认为问题不在于授权某些用户访问WCF,而是关于“在抛出异常或其他情况时如何不重定向到默认登录页面” – user1147981 2015-12-11 16:45:50