dongyan3562 2011-07-06 13:48
浏览 703
已采纳

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

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 />
";
}
echo "<pre>
";
echo htmlspecialchars($client->__getLastRequest())."
";
echo "Response:
".htmlspecialchars($client->__getLastResponse())."
";
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.

  • 写回答

1条回答 默认 最新

  • dongpu1908 2011-07-06 14:41
    关注

    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 />
    ";
    }
    
    echo "<pre>";
    echo htmlspecialchars($client->__getLastRequestHeaders())."
    ";
    echo htmlspecialchars($client->__getLastRequest())."
    ";
    echo "Response:
    ".htmlspecialchars($client->__getLastResponseHeaders())."
    ";
    echo htmlspecialchars($client->__getLastResponse())."
    ";
    echo "</pre>"; 
    
    var_dump($result);
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证