简体   繁体   English

身份验证模式=“表单”导致WCF服务中的重定向

[英]Authentication mode=“Forms” causing redirect in WCF service

I have a WCF end point inside my .NET 4.0 Web Application project. 我的.NET 4.0 Web应用程序项目中有一个WCF端点。 Using the VS2010 WCF Test Client, I can connect to the service correctly. 使用VS2010 WCF测试客户端,我可以正确连接到服务。 However when I go to use the service I get a generic error message: 但是,当我去使用该服务时,我收到一般错误消息:

The content type text/html; 内容类型text / html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). charset =响应消息的UTF-8与绑定的内容类型不匹配(text / xml; charset = utf-8)。 If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. 如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。 The first 1024 bytes of the response were: 响应的前1024个字节是:

When I looked at the requests on IIS Express I got the following: 当我查看IIS Express上的请求时,我得到以下内容:

Request started: POST http://machinename:port/Services/Services.svc 请求已启动:POST http:// machinename:port / Services / Services.svc

Request started: GET http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1 请求已启动: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 请求已开始: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 请求已结束:“http:// machinename:port / Services / Services.svc”,HTTP状态为302.0

Request ended: "http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1" with HTTP status 302.0 请求已结束:“http:// machinename:port / Services / Services.svc?AspxAutoDectectCookieSupport = 1”,HTTP状态为302.0

Request ended: "http://machinename:port/Services/Services.svc?AspxAutoDectectCookieSupport=1" with HTTP status 200.0 请求已结束:“http:// machinename:port / Services / Services.svc?AspxAutoDectectCookieSupport = 1”,HTTP状态为200.0

So it seems like after POSTing to the service it is getting redirected to the standard web page for the service. 因此,在POST到服务之后,它似乎被重定向到服务的标准网页。 Yet when I remove: 然而,当我删除:

<authentication mode="Forms">
<forms cookieless="AutoDetect" loginUrl="~/Security/LoginClient.aspx" name="FORMAUTH" />

from the web.config it works. 从web.config它的工作原理。 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. 我试图从身份验证中删除该服务所在的文件夹(http://stackoverflow.com/questions/5593720/authentication-mode-forms-causing-errors-in-wcf-end-point),但问题仍然存在。

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. 虽然当我通过IIS Express 7.5运行它时使用Visual Studio开发服务器(Cassini),但无论是否使用身份验证,都会发生相同的错误。

You have to provide authorization for your web services to be contacted anonymously in your web.config: 您必须提供在web.config中匿名联系的Web服务的授权:

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

This assumes that you keep all of your services in a folder called MyWebServices relative to the root of the application. 这假设您将所有服务保存在相对于应用程序根目录的名为MyWebServices的文件夹中。 You have to allow * or it will force a login for access. 您必须允许*或强制登录才能访问。

I am experiencing the same issue as soon as I use the machinename instead of localhost in the service address. 我在服务地址中使用machinename而不是localhost时遇到同样的问题。 I did try to use a "baseAddressPrefixFilters" but without success. 我确实尝试使用“baseAddressPrefixFilters”但没有成功。

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

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

It only works with an address like http://localhost/VirtualSite/MyService.svc without a domain and without the baseAddressPrefixFilters ! 它只适用于http://localhost/VirtualSite/MyService.svc这样的地址,没有域,也没有baseAddressPrefixFilters!

V. V.

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

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