NuSOAP: how to change content-type of request?

后端 未结 5 1392
自闭症患者
自闭症患者 2020-12-07 03:24

When consuming a .NET WCF webservice I get the following response (error):

Unsupported HTTP response status 415 Cannot process the message because t

相关标签:
5条回答
  • 2020-12-07 03:49

    It looks like there's a slight omission in the NuSOAP library... it assumes that the content headers MUST be "text/xml", so if your client is attempting to connect to a service that outputs application/soap+xml headers, you'll end up with errors like:

    Response not of type text/xml: application/soap+xml; charset=utf-8

    To test this, you may benefit from the following little function pattern, which I used to login to a SOAP service. Remember, print out the client object! You may not actually get a result to look at!

    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 (i.e. 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 got nothing, but when I printed out 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 for 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 does is it lets NuSOAP handle responses that issue an "application/soap+xml" header (which is a valid xml header).

    0 讨论(0)
  • 2020-12-07 03:49

    I was stuck on this as well.

    The secret is in the web.config Change wsHttpBinding to basicHttpBinding

    Like so:

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

    Hope that helps! /Erik

    0 讨论(0)
  • 2020-12-07 03:51

    i know this is an old post, but i ran in to this page looking for an answer.

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

    something like this should do the trick,

    $client = new SoapClient("some.wsdl", array('soap_version' => SOAP_1_1));
    
    0 讨论(0)
  • 2020-12-07 03:52

    You can specify the encoding of NuSOAP streams with the webservices like that :

    $client = new nusoap_client($params);
    $client->soap_defencoding = 'UTF-8';
    
    0 讨论(0)
  • 2020-12-07 03:55

    This worked for me:

    $client = new nusoap_client($params);

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

    The answer that is ticked as correct is not for NUSOAP therefore not the appropriate answer.

    0 讨论(0)
提交回复
热议问题