使用PHP Soap客户端的问题

时间:2011-12-14 19:57:11

标签: php soap-client

我可以通过这种配置访问此Web服务:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <Executar xmlns="http://localhost/I9ProWebService">
      <Servico>string</Servico>
      <conteudoXML>string</conteudoXML>
    </Executar>
  </soap:Body>
</soap:Envelope>

所以我尝试了这个:

$client = new soapclient('https://domain/webservice/I9ProWebService.asmx?WSDL');
printf($client->Executar("ListarTomador","<i9proerp><listar_tomador id_pessoa_corretor     =\"205\" /></i9proerp>"));

它显示此错误:

  

System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---&GT; System.NullReferenceException:未将对象引用设置为对象的实例。在I9ProWebService.Executar(String Servico,String conteudoXML)---内部异常堆栈跟踪结束---

2 个答案:

答案 0 :(得分:0)

您是否尝试过使用htmlentities或类似代码将您要发送的XML编码为第二个参数?这可能会导致SOAP客户端发送的XML出现问题。

编辑:为了查看PHP SOAP客户端发送的XML及其返回的内容,您可以使用$client->__getLastRequest()$client->__getLastResponse()并将结果与​​您的结果进行比较soapUI电话。

答案 1 :(得分:0)

我找到了解决问题的方法。

$client = new SoapClient("http://domain/webservice/I9ProWebService.asmx?WSDL", array("features" => SOAP_SINGLE_ELEMENT_ARRAYS, "encoding" => "utf-8","trace"=> TRUE));
$strVariavel = "<ns1:conteudoXML><i9proerp><listar_tomador id_pessoa =\"999\"/></i9proerp></ns1:conteudoXML>";
$soapvar = new SoapVar($strVariavel, 147);
$xml = $client->ExecutarXML(array('Servico'=>'ListarTomador','conteudoXML'=>$soapvar));
print_r($xml);

和voilá

问题在于它返回和对象而不是我期望的XML ......

它返回:

 stdClass Object
 (
     [ExecutarXMLResult] => stdClass Object
         (
                 [any] => <i9proerp xmlns=""><listatomador id_pessoa="5251" nm_pessoa="nome1"  nr_cnpj_cpf="132132121332"/><listatomador id_pessoa="939" nm_pessoa="nome2" nr_cnpj_cpf="3213213123213"/></i4proerp>
            )
       )

所以,我必须发现如何处理它。是打开another question吗?