Search code examples
c#phpxamarin.androidnusoap

UTF-8 != utf-8 with NuSoap and C#


I am using Xamarin to make a Android APP using a CodeIgnitor back end. For the soap connection I am using NuSoap. Initially I was getting the error about not support UTF-8 but resolved that by adding $this->nusoap_server->soap_defencoding = 'UTF-8' and changing a couple spots in NuSoap that seemed to not use those setting.

I am not getting the below error, my first guess it because of the upper/lower case thing but I'm not sure. It seems to only occur when sending complex types.

System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=System.Private.CoreLib
StackTrace:
  at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
  at System.Threading.Tasks.Task.Wait()
  at tbq_test.Program.Main(String[] args) in 
  D:\WebSites\Projects\tbq-test\tbq-test\Program.cs:line 20

Inner Exception 1:
ProtocolException: 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).

Solution

  • Try adding

    header('Content-Type: text/xml; charset=utf-8');

    before sending the data from PHP. Your error complains about the expected response content type not matching. You are sending text/html.