title: Web Service XML response being received as "text/plain". (Yet another content type error.)
body: <p>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.</p>
  
  <p>I've reviewed the dozens of similar S.O. posts regarding this error and have ruled out the more common possibilities:</p>
  
  <ol>
  <li>I can see in the response that it's not an Error page coming back (as discussed <a href="https://stackoverflow.com/questions/5243929/wcf-service-client-the-content-type-text-html-charset-utf-8-of-the-response-me?rq=1">here</a>).</li>
  <li>I don't appear to have a binding mismatch issue (as discussed <a href="https://stackoverflow.com/questions/8637652/wcf-charset-utf-8-of-the-response-message-does-not-match-the-content-type-of-the">here</a>).  My app and
  the web service are both using SOAP 1.1 and I have "basicHttpBinding" specified.</li>
  <li>The response included in my error message appears to show valid XML
  that includes the user and response variables that I want.</li>
  <li>I can see in the Web Service log files that the login method is
  fully executing without throwing an exception.</li>
  <li>I pasted the XML response into the W3Schools validator with no
  error.</li>
  </ol>
  
  <p>What else could be causing my error, and why isn't this being recognized as valid XML?</p>
  
  <p>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.</p>
  
  <p><strong>Here are the relevant excerpts from my login code:</strong></p>
  
  <pre><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.
  </code></pre>
  
  <p><strong>Here is what the binding looks like in my Web.Config:</strong></p>
  
  <pre><code>&lt;system.serviceModel&gt;
    &lt;bindings&gt;
      &lt;basicHttpBinding&gt;
        &lt;binding name="AuthenticationServiceSoapBinding" /&gt;
      &lt;/basicHttpBinding&gt;
    &lt;/bindings&gt;
    &lt;client&gt;
      &lt;endpoint address="http://mywebserviceurl"
        binding="basicHttpBinding" bindingConfiguration="AuthenticationServiceSoapBinding"
        contract="MyNamespace.AuthenticationService" name="AuthenticationServiceImplPort" /&gt;
    &lt;/client&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p><strong>Here is my Error Message:</strong></p>
  
  <blockquote>
    <p>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: '</p>
  </blockquote>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;soap:Body&gt;
  &lt;loginReponse xmlns="urn:xxxx"&gt;
  &lt;authKey&gt;xxxx&lt;/authKey&gt;
  &lt;authMetadata&gt;
  &lt;IPaddress&gt;https://MyWebApplicationURL&lt;/IPaddress&gt;
  &lt;loginTimestamp&gt;xxxx&lt;/loginTimestamp&gt;&lt;levelOfAssurance&gt;
  &lt;AuthMechanism&gt;xxxx&lt;/AuthMechanism&gt;
  &lt;VettingAssertion&gt;xxxx&lt;/VettingAssertion&gt;
  &lt;/levelOfAssurance&gt;
  &lt;/authMetadata&gt;
  &lt;errorText&gt;&lt;/errorText&gt;
  &lt;successfulLoginFlag&gt;true&lt;/successfulLoginFlag&gt;
  &lt;userSummary&gt;
  &lt;GUID&gt;xxxx&lt;/GUID&gt;
  &lt;commonName&gt;xxxx&lt;/commonName&gt;
  &lt;loginName&gt;xxxx&lt;/loginName&gt;
  &lt;/userSummary&gt;
  &lt;passwordExpiryDays&gt;xxxx&lt;/passwordExpiryDays&gt;&lt;/loginReponse&gt;
  &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <blockquote>
    <p>'.</p>
    
    <p>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)</p>
    
    <p>Exception rethrown at [0]:     at
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
    reqMsg, IMessage retMsg)    at
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;
    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<br>
    at MyNamespace.Forms.TestWebService.TestLogin_Click(Object sender,
    EventArgs e) in C:...\TestWebService.aspx.cs:line 284</p>
  </blockquote>
  
  <p><strong>Here is what my response from the Web Service looks like in WireShark:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/VxMkH.png" alt="WireShark Screenshot"></p>