繁体   English   中英

NuSOAP:如何更改内容类型的请求?

[英]NuSOAP: how to change content-type of request?

在使用.NET WCF Web服务时,我得到以下响应(错误):

不支持的HTTP响应状态415无法处理消息,因为内容类型为'text / xml; charset = UTF-8'不是预期的类型'application / soap + xml; 字符集= UTF-8' 。

如何更改内容类型? 我在NuSOAP论坛/文档中找不到它,或者我可能会忽略某些东西....

我知道这是一个旧帖子,但我跑到这个页面寻找答案。

application/soap+xml是使用SOAP 1.2时传递的内容类型, text/xml与SOAP 1.1一起使用,

像这样的东西应该做的伎俩,

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

您可以使用以下Web服务指定NuSOAP流的编码:

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

看起来NuSOAP库中有一点遗漏...它假设内容标题必须是“text / xml”,所以如果你的客户端试图连接到输出application / soap + xml标题的服务,你'最终会出现以下错误:

响应不是text / xml类型:application / soap + xml; 字符集= utf-8的

为了测试这一点,您可以从以下小功能模式中受益,我用它来登录SOAP服务。 请记住,打印出客户端对象! 你可能实际上没有看到结果!

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
}

当我打印我的$ result时,我什么也没得到,但是当我打印出$ client对象时,我发现有错误。

我实现的小黑客是在7500行左右的nusoap.php文件中。查找这个if语句:

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

并将其更改为:

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;
}

所有这一切都是让NuSOAP处理发出“application / soap + xml”标头(这是一个有效的xml标头)的响应。

这对我有用:

$ client = new nusoap_client($ params);

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

答案是正确的答案不适用于NUSOAP,因此不是合适的答案。

我也被困在这上面了。

秘密在web.config中将wsHttpBinding更改为basicHttpBinding

像这样:

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

希望有所帮助! /埃里克

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM