Authentication mode=“Forms” causing redirect in WCF service

眉间皱痕 提交于 2019-12-11 23:39:28

问题


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.


回答1:


You have to provide authorization for your web services to be contacted anonymously in your web.config:

<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. You have to allow * or it will force a login for access.




回答2:


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.

<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 :(

It only works with an address like http://localhost/VirtualSite/MyService.svc without a domain and without the baseAddressPrefixFilters !

V.



来源:https://stackoverflow.com/questions/5596304/authentication-mode-forms-causing-redirect-in-wcf-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!