I’m trying to call a php webservice using WCF. I googled some public php services to see if I could replicate the error I was receiving and I created 2 different unit tests to demonstrate.
The test that failed I get the following error: System.ServiceModel.ProtocolException: The content type text/xml; charset=ISO-8859-1 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 601 bytes of the response were: ‘
Here are the unit tests:
[TestMethod] public void WCF_Call_To_SiteInspect() { //This service doesn't work. It gets the same communication error as our own servers var soapClien = new SiteInspect.SiteInspectPortClient(); var response = soapClien.doSiteInspect('Any', 'Any', 'www.google.com'); Assert.IsTrue(response.serverTime.Length > 0); } [TestMethod] public void WCF_Call_To_FinnService() { //This service works.... in looking at the wsdl it appears that it references a separate wsdl file. Is this the reason? var soapClient = new NuSoapFinnService.finnwordsPortTypeClient(); var finnLyric = soapClient.getRandomNeilFinnLyric('text'); Assert.IsTrue(finnLyric.Length > 0); }
The test case on the bottom (the Finn service) passed at the following URL: http://www.nickhodge.com/nhodge/finnwords/finnwords.wsdl
The first test case failed given the following URL: http://www.flash-db.com/services/ws/siteInspect.wsdl
The only difference I can see in the wsdl is the Finn service references an extraneous file. xmlns:tns=’http://www.nickhodge.com/nhodge/finnwords/finnwords.wsdl . Is this bug with WCF that expects the wsdl in a specific format?
Make sure to set the UTF-8 encoding using soap_defencoding in the PHP code.
If you want some more related information, see this blog post.