用于复杂XML请求的PHP SOAP客户端

时间:2018-06-26 22:30:24

标签: php soap-client

我正在尝试使用以下XML创建请求:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<VertexEnvelope xmlns="urn:vvvvvvvv:o-series:tps:8:0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:vvvvvvv:o-series:tps:8:0 vvvvvv_Envelope.xsd">
         <Login>
            <UserName>xxxxxxx</UserName>
            <Password>xxxxxxxx</Password>
         </Login>
         <QuotationRequest documentDate="2018-02-07" transactionType="SALE">
  <Currency isoCurrencyCodeAlpha="USD"/>
  <Seller>
    <Company>2</Company>
    <Division>340</Division>
  </Seller>
  <Customer>
    <Destination taxAreaId="230132823">
      <City>BARAGA</City>
      <MainDivision>MI</MainDivision>
      <PostalCode>49908-9204</PostalCode>
    </Destination>
  </Customer>
  <LineItem lineItemNumber="1">
    <Seller>
      <PhysicalOrigin taxAreaId="261835449">
        <City>ST. CHARLES</City>
        <MainDivision>MO</MainDivision>
        <PostalCode>63301</PostalCode>
      </PhysicalOrigin>
    </Seller>
    <Customer>
      <CustomerCode classCode="20683"/>
    </Customer>
    <Product productClass="143"/>
    <Quantity>1</Quantity>
    <UnitPrice>6.95</UnitPrice>
    <FlexibleFields>
      <FlexibleCodeField fieldId="7">SP STD</FlexibleCodeField>
    </FlexibleFields>
  </LineItem>
  <LineItem lineItemNumber="2">
    <Customer>
      <CustomerCode classCode="20683"/>
    </Customer>
    <Product productClass="276"/>
    <Quantity>1</Quantity>
    <UnitPrice>2</UnitPrice>
  </LineItem>
</QuotationRequest>
</VertexEnvelope>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我正在使用WSDL方法。

我正在上面的“ xml”中设置变量$xml

其余大部分代码为:

$client = new SoapClient($wsdl, array(  'soap_version' => SOAP_1_1,
                                        'trace' => true,
     'ssl'   => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
      ),
      'Login' => array (
                 'UserName' => 'xxxxxxxxx',
                 'Password' => 'xxxxxxx',
      ),
                                      ));


$client->__setLocation('https://vvvvvvvv.yyyyyyyyy.com/vvvvvv-ws/services/CalculateTax80');


    $args = array(new SoapVar($xml, XSD_ANYXML));
    echo "<hr>args<br>";
    print_r($args)."<br><br>";

    print "<br><br>";

    #  var_dump($client->__getFunctions());
    $obj = $client->calculateTax80($xml);
    print "var dump obj:<br><br>";
    var_dump($obj);
    #print "var dump getLastRequest<br><br>";
    #       var_dump($client->getLastRequest());
    print "<br><br>";

我得到的输出是:

args
Array ( [0] => SoapVar Object ( [enc_type] => 147 [enc_value] =>  username password  2 340  BARAGA MI 49908-9204   ST. CHARLES MO 63301    1 6.95 SP STD    1 2      ) ) 

错误信息是:

string(9) "SoapFault" object(SoapFault)#5 (10) { ["message":protected]=> string(30) "java.lang.NullPointerException" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(50) "/soapservices/xxxxxx05.php" ["line":protected]=> int(103) ["trace":"Exception":private]=> array(2) { [0]=> array(6) { ["file"]=> string(50) "//soapservices/xxxxxx05.php" ["line"]=> int(103) ["function"]=> string(6) "__call" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(14) "calculateTax80" [1]=> array(1) { [0]=> string(1570) " xxxxxxxx xxxxxx  2 340  BARAGA MI 49908-9204   ST. CHARLES MO 63301    1 6.95 SP STD    1 2     " } } } [1]=> array(6) { ["file"]=> string(50) "/var/www/html/ecommerce/soapservices/testphp05.php" ["line"]=> int(103) ["function"]=> string(14) "calculateTax80" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(1570) " xxxxxxx xxxxx  2 340  BARAGA MI 49908-9204   ST. CHARLES MO 63301    1 6.95 SP STD    1 2     " } } } ["previous":"Exception":private]=> NULL ["faultstring"]=> string(30) "java.lang.NullPointerException" ["faultcode"]=> string(14) "soapenv:Server" ["detail"]=> object(stdClass)#3 (1) { ["vvvvvException"]=> object(stdClass)#4 (2) { ["exceptionType"]=> string(20) "NullPointerException" ["rootCause"]=> string(30) "java.lang.NullPointerException" } } } 

0 个答案:

没有答案