0

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.

SmudgerDan
  • 413
  • 5
  • 16

2 Answers2

2

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.

Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
  • This is what I thought it was, which was why I asked it here [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) but having tried that it still redirects me – SmudgerDan Jun 09 '11 at 15:02
  • Not working. If any issues is thrown in the WCF, it still redirects to the default loginUrl. I don't think the problem is about authorizing some users to the WCF, but about "How to not redirect to the default login page when an exception or something is thrown" – UIChris Dec 11 '15 at 16:45
0

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.

Valery Letroye
  • 1,035
  • 11
  • 19