PHP SOAP 返回 SOAP 错误:服务器无法使用 .asmx Web 服务处理请求

发布于 2024-11-18 12:13:12 字数 2678 浏览 1 评论 0原文

我很难让 SOAP 请求正常工作,这需要 XML 字符串作为输入。

它抛出

“SOAP 错误:服务器无法处理请求。 ---> 值不能为空。参数名称:s”

无论我发送什么输入,我都使用了 nusoap 但无济于事, PHP 肥皂库。 我使用的代码是:

<?
$aOptions = array(
'location' => 'http://webserviceurl.asmx',
'uri' => 'http://tempuri.org/',
"style" => SOAP_RPC,
"use" => SOAP_ENCODED
);
$client = new SOAPClient(null, $aOptions);

$request ='<item xmlns="rmsItem">
      <columns>
        <column>description</column>
        <column>department</column>
        <column>brand</column>
        <column>lastsold</column>
        <column>lastupdated</column>
        <column>quantityonhand</column>
        <column>weight</column>
      </columns>
      <filters>
        <filter>
          <filterColumn>quantityonhand</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>20</filterValue>
        </filter>
        <filter>
          <filterColumn>lastsold</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>01-01-2005</filterValue>
        </filter>
      </filters>
      <sortColumns>
        <sortColumn>
          <sortColumnName>lastsold</sortColumnName>
          <sortType>ascending</sortType>
        </sortColumn>
        <sortColumn>
          <sortColumnName>quantityonhand</sortColumnName>
          <sortType>descending</sortType>
        </sortColumn>
      </sortColumns>
    </item>';

//$result = $client->__soapCall('getAllInfo',array('infoRequestXml'=>(string)($request),'errorMessage'=>'') ,array('soapaction' => 'http://webserviceurl/getAllInfo'));

$soapvar = new SoapVar($request , XSD_ANYXML);

$params = array("infoRequestXml" => $soapvar);

//print_r($params);
//$result = $this->soapclient->__soapCall("SaveItem", array("parameters"=>$params), null, $this->soapheaders);
try
{
$result=$client->__soapCall('getAllInfo',array("parameters"=>$params),array('soapaction' => 'http://webserviceurl/getAllInfo'));
}
catch (SoapFault $e) {
    echo "SOAP Fault: ".$e->getMessage()."<br />\n";
}
echo "<pre>\n";
echo htmlspecialchars($client->__getLastRequest())."\n";
echo "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
echo "</pre>"; 

var_dump($result);

?>

过去两天我一直在用头撞墙,在谷歌上搜索这个问题,但没有得到解决或指导我解决的答案。

任何能够阐明这一点的人都将受到高度赞赏。 提前致谢。

I am having difficulty in getting a SOAP request working properly , which requires XML string as input.

It's throwing

"SOAP Fault: Server was unable to process request. ---> Value cannot be null. Parameter name: s"

no matter what input i send , i have used nusoap but to no avail , PHP soap library.
The code i am using is:

<?
$aOptions = array(
'location' => 'http://webserviceurl.asmx',
'uri' => 'http://tempuri.org/',
"style" => SOAP_RPC,
"use" => SOAP_ENCODED
);
$client = new SOAPClient(null, $aOptions);

$request ='<item xmlns="rmsItem">
      <columns>
        <column>description</column>
        <column>department</column>
        <column>brand</column>
        <column>lastsold</column>
        <column>lastupdated</column>
        <column>quantityonhand</column>
        <column>weight</column>
      </columns>
      <filters>
        <filter>
          <filterColumn>quantityonhand</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>20</filterValue>
        </filter>
        <filter>
          <filterColumn>lastsold</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>01-01-2005</filterValue>
        </filter>
      </filters>
      <sortColumns>
        <sortColumn>
          <sortColumnName>lastsold</sortColumnName>
          <sortType>ascending</sortType>
        </sortColumn>
        <sortColumn>
          <sortColumnName>quantityonhand</sortColumnName>
          <sortType>descending</sortType>
        </sortColumn>
      </sortColumns>
    </item>';

//$result = $client->__soapCall('getAllInfo',array('infoRequestXml'=>(string)($request),'errorMessage'=>'') ,array('soapaction' => 'http://webserviceurl/getAllInfo'));

$soapvar = new SoapVar($request , XSD_ANYXML);

$params = array("infoRequestXml" => $soapvar);

//print_r($params);
//$result = $this->soapclient->__soapCall("SaveItem", array("parameters"=>$params), null, $this->soapheaders);
try
{
$result=$client->__soapCall('getAllInfo',array("parameters"=>$params),array('soapaction' => 'http://webserviceurl/getAllInfo'));
}
catch (SoapFault $e) {
    echo "SOAP Fault: ".$e->getMessage()."<br />\n";
}
echo "<pre>\n";
echo htmlspecialchars($client->__getLastRequest())."\n";
echo "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
echo "</pre>"; 

var_dump($result);

?>

I am banging my head against a wall from last two days, searched google for this problem but got no answer that solves or guide me through.

Anyone who can throw some light on this will be highly appreciated.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2024-11-25 12:13:12

不要通过 SOAPVar 运行 XML,并且如果可以的话,请利用 Web 服务的 WSDL 选项:

<?php

$client = new SOAPClient(
    'http://webserviceurl.asmx?WSDL',
    array(
        'location' => 'http://webserviceurl.asmx',
        'trace' => 1,
        'style' => SOAP_RPC,
        'use' => SOAP_ENCODED,
    )
);

$request = '<item xmlns="rmsItem">
      <columns>
        <column>description</column>
        <column>department</column>
        <column>brand</column>
        <column>lastsold</column>
        <column>lastupdated</column>
        <column>quantityonhand</column>
        <column>weight</column>
      </columns>
      <filters>
        <filter>
          <filterColumn>quantityonhand</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>20</filterValue>
        </filter>
        <filter>
          <filterColumn>lastsold</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>01-01-2005</filterValue>
        </filter>
      </filters>
      <sortColumns>
        <sortColumn>
          <sortColumnName>lastsold</sortColumnName>
          <sortType>ascending</sortType>
        </sortColumn>
        <sortColumn>
          <sortColumnName>quantityonhand</sortColumnName>
          <sortType>descending</sortType>
        </sortColumn>
      </sortColumns>
    </item>';

$result = array();

$params = array("infoRequestXml" => $request);

try {
    $result = $client->__soapCall('getAllInfo', array("parameters"=>$params));
} catch (SoapFault $e) {
    echo "SOAP Fault: ".$e->getMessage()."<br />\n";
}

echo "<pre>";
echo htmlspecialchars($client->__getLastRequestHeaders())."\n";
echo htmlspecialchars($client->__getLastRequest())."\n";
echo "Response:\n".htmlspecialchars($client->__getLastResponseHeaders())."\n";
echo htmlspecialchars($client->__getLastResponse())."\n";
echo "</pre>"; 

var_dump($result);

?>

Don't run the XML through SOAPVar, and take advantage of the WSDL option of your web service if you can:

<?php

$client = new SOAPClient(
    'http://webserviceurl.asmx?WSDL',
    array(
        'location' => 'http://webserviceurl.asmx',
        'trace' => 1,
        'style' => SOAP_RPC,
        'use' => SOAP_ENCODED,
    )
);

$request = '<item xmlns="rmsItem">
      <columns>
        <column>description</column>
        <column>department</column>
        <column>brand</column>
        <column>lastsold</column>
        <column>lastupdated</column>
        <column>quantityonhand</column>
        <column>weight</column>
      </columns>
      <filters>
        <filter>
          <filterColumn>quantityonhand</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>20</filterValue>
        </filter>
        <filter>
          <filterColumn>lastsold</filterColumn>
          <operator>greaterthan</operator>
          <filterValue>01-01-2005</filterValue>
        </filter>
      </filters>
      <sortColumns>
        <sortColumn>
          <sortColumnName>lastsold</sortColumnName>
          <sortType>ascending</sortType>
        </sortColumn>
        <sortColumn>
          <sortColumnName>quantityonhand</sortColumnName>
          <sortType>descending</sortType>
        </sortColumn>
      </sortColumns>
    </item>';

$result = array();

$params = array("infoRequestXml" => $request);

try {
    $result = $client->__soapCall('getAllInfo', array("parameters"=>$params));
} catch (SoapFault $e) {
    echo "SOAP Fault: ".$e->getMessage()."<br />\n";
}

echo "<pre>";
echo htmlspecialchars($client->__getLastRequestHeaders())."\n";
echo htmlspecialchars($client->__getLastRequest())."\n";
echo "Response:\n".htmlspecialchars($client->__getLastResponseHeaders())."\n";
echo htmlspecialchars($client->__getLastResponse())."\n";
echo "</pre>"; 

var_dump($result);

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文