NuSOAP: how to change the content type of a request?

When using the .NET WCF web service, I get the following response (error):

Unsupported HTTP response status 415 The message cannot be processed because the content type 'text / xml; encoding = UTF-8' was not the expected type 'application / soap + xml'; encoding = UTF-8 '.

How to change the type of content? I cannot find it in the NuSOAP forums / docs, or I could ignore something ...

+4
source share
5 answers

I know this is an old post, but I went to this page looking for an answer.

application/soap+xml is the content type passed when using SOAP 1.2, text/xml used with SOAP 1.1,

something like this should do the trick,

 $client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_1)); 
+9
source

You can specify the encoding of NuSOAP streams using the following web services:

 $client = new nusoap_client($params); $client->soap_defencoding = 'UTF-8'; 
+3
source

It seems like a slight omission in the NuSOAP library ... it is assumed that the content headers MUST be "text / xml", so if your client tries to connect to a service that displays application / soap headers + xml, you will get errors, for example:

The answer is not text like / xml: application / soap + xml; encoding = UTF-8

To verify this, you can use the following small function template that I used to log in to the SOAP service. Remember, print the client object! In fact, you can’t get the result!

 require_once('path/to/downloaded/libraries/nusoap.php'); var $endpoint = 'https://somedomain.com/path/to/soap/server/Login'; var $client; // the soapclient object function SOAP_Login() { $this->client = new soapclient($this->endpoint); $err = $this->client->getError(); if ($err) { // Display the error echo '<p><b>SOAP Constructor error: ' . $err . '</b></p>'; exit; // At this point, you know the call that follows will fail } $params = array( 'some' => 'thing.. depends on what the WSDL expects' ); $result = $this->client->call('someFunction', $params); print_r($result); // Without the fix, this prints nothing (ie false) !!! print_r($this->client); // Instead, look at the state of the client object, specifically error_str and debug_str } 

When I printed my $ result, I didn’t get anything, but when I printed the $ client object, I could see that there were errors.

The little hack I implemented was in the nusoap.php file, around line 7500. Look at this if-statement:

 if (!strstr($headers['content-type'], 'text/xml')) { $this->setError('Response not of type text/xml: ' . $headers['content-type']); return false; } 

And change it to this:

 if (!strstr($headers['content-type'], 'text/xml') && !strstr($headers['content-type'], 'application/soap+xml') ) { $this->setError('Response not of type text/xml: ' . $headers['content-type']); return false; } 

All this allows NuSOAP to handle responses that invoke the header "application / soap + xml" (which is a valid xml header).

+2
source

I am also stuck on this.

Secret in web.config Change wsHttpBinding to basicHttpBinding

Same:

 <endpoint address="" binding="basicHttpBinding" contract="YourProject.View.Whatever.IYourService"> 

Hope this helps! / Eric

0
source

This worked for me:

$ client = new nusoap_client ($ params);

$ client-> soap_defencoding = 'UTF-8';

The answer that is marked as correct is not for NUSOAP, so the answer is not appropriate.

0
source

Source: https://habr.com/ru/post/1285690/


All Articles