PHP中的Soap API集成:SoapClient错误

时间:2013-09-06 06:24:05

标签: php xml web-services soap wsdl

当我在sopaUI中使用XML时,结果很好,但是当我使用下面的PHP代码时,结果出现空白,我收到此错误:Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Saia.Presentation。我认为问题出现在Soap标题中,因为当我注释掉参数时,结果没有变化。

从我获得wsdl文件和架构的链接:http://www.saiasecure.com/webservice/pickup/n_Create.asp

$client = new SoapClient("http://www.saiasecure.com/webservice/pickup/soap.asmx?wsdl",array( 'trace' => 1,
'exceptions' => true,'features' => SOAP_SINGLE_ELEMENT_ARRAYS, ));

$params = array("UserID" => '*******',
        "Password" => '*****',
        "TestMode" => "Y",
        "AccountNumber" => '******',
        "CompanyName" => 'TESTING NAME',
        "Street" => 'TESTING STREET',
        "Box" => 'TESTING BOX',
        "City" => 'LOS ANGELES',
        "State" => 'CA',
        "Zipcode" => '90001',
        "ContactName" => 'TESTING CONTACT',
        "ContactPhone" => '1234567890',
        "PickupDate" => '2013-09-24',
        "ReadyTime" => '13:00:00',
        "CloseTime" => '17:00:00',
        "SpecialInstructions" => 'Nothing',
         "Details" => array("DetailItem" => array("DestinationZipcode" => '70364', "Pieces" => '5', "Package" => 'SK',"Weight" => '100', "Freezable" => 'N') ));
    //print('<pre>');print_r($params);  
$return = $client->Create($params);

1 个答案:

答案 0 :(得分:0)

如果您查看WSDL,您会看到Create操作参数必须包含一个request元素,该元素指向实际的Create对象参数(您可以发送)就像你使用关联数组一样。)

我必须说WSDL不是很正确,因为相同的元素名称,意思是Create两次用于不同的定义。一次为element,一次为complexType

要明确的是,您必须使用实际代码执行此操作:$return = $client->Create(array('request'=>$params));并且它应该有效。