I am attempting to develop a web application that submits a simple login request to a web service using WCF, but I keep getting "content type text/plain of the response message does not match" errors, even though the web service appears to be returning valid XML.
I've reviewed the dozens of similar S.O. posts regarding this error and have ruled out the more common possibilities:
- I can see in the response that it's not an Error page coming back (as discussed here).
- I don't appear to have a binding mismatch issue (as discussed here). My app and the web service are both using SOAP 1.1 and I have "basicHttpBinding" specified.
- The response included in my error message appears to show valid XML that includes the user and response variables that I want.
- I can see in the Web Service log files that the login method is fully executing without throwing an exception.
- I pasted the XML response into the W3Schools validator with no error.
What else could be causing my error, and why isn't this being recognized as valid XML?
I am using .Net 4.0 and Visual Studio 2010 for my application, which is communicating with a Java/Tomcat web service on a separate server.
Here are the relevant excerpts from my login code:
AuthenticationServiceClient client = new AuthenticationServiceClient(strPortName, strURL);
client.Open();
UserCredentials credentials = new UserCredentials();
credentials.userName = TestUsername;
credentials.password = TestPassword;
LoginResponse response = client.login(credentials); // Using WCF.
Here is what the binding looks like in my Web.Config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticationServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mywebserviceurl"
binding="basicHttpBinding" bindingConfiguration="AuthenticationServiceSoapBinding"
contract="MyNamespace.AuthenticationService" name="AuthenticationServiceImplPort" />
</client>
</system.serviceModel>
Here is my Error Message:
Error testing connection to web service at "WebServiceURL": System.ServiceModel.ProtocolException: The content type text/plain 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 788 bytes of the response were: '
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<loginReponse xmlns="urn:xxxx">
<authKey>xxxx</authKey>
<authMetadata>
<IPaddress>https://MyWebApplicationURL</IPaddress>
<loginTimestamp>xxxx</loginTimestamp><levelOfAssurance>
<AuthMechanism>xxxx</AuthMechanism>
<VettingAssertion>xxxx</VettingAssertion>
</levelOfAssurance>
</authMetadata>
<errorText></errorText>
<successfulLoginFlag>true</successfulLoginFlag>
<userSummary>
<GUID>xxxx</GUID>
<commonName>xxxx</commonName>
<loginName>xxxx</loginName>
</userSummary>
<passwordExpiryDays>xxxx</passwordExpiryDays></loginReponse>
</soap:Body>
</soap:Envelope>
'.
Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at MyNamespace.AuthenticationService.AuthenticationService.login(loginRequest request) at MyNamespace.AuthenticationService.AuthenticationServiceClient.MyNamespace.AuthenticationService.AuthenticationService.login(loginRequest request) in C:...\AuthenticationService\Reference.cs:line 1716 at MyNamespace.AuthenticationService.AuthenticationServiceClient.login(UserCredentials credentials) in C:...\AuthenticationService\Reference.cs:line 1722
at MyNamespace.Forms.TestWebService.TestLogin_Click(Object sender, EventArgs e) in C:...\TestWebService.aspx.cs:line 284
Here is what my response from the Web Service looks like in WireShark: