第一次使用PHP SOAP客户端
我已经开始编写一些在PHP中使用SOAP的代码 设法让我的代码登录和验证,这是一个开始 我最初有以下代码:第一次使用PHP SOAP客户端,php,soap,Php,Soap,我已经开始编写一些在PHP中使用SOAP的代码 设法让我的代码登录和验证,这是一个开始 我最初有以下代码: $params = array( "Parcels" => 1, "RecipientAddress" => "123 Any Street, Any Town, Anywhere", "RecipientName" => "Joe Bloggs", "CollectionDate" => "2019-11-11", ); // Invoke WS
$params = array(
"Parcels" => 1,
"RecipientAddress" => "123 Any Street, Any Town, Anywhere",
"RecipientName" => "Joe Bloggs",
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
返回了以下消息:
Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client] Missing Recipient Address Element 'RecipientName' in /home/thisone/public_html/despatchbayservices.php:17 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(17): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 17
我已尝试将代码更改为:
$params = array(
"Parcels" => 1,
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
// Print WS response
var_dump($response);
它返回了这个:
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'RecipientAddress' property in /home/thisone/public_html/despatchbayservices.php:18 Stack trace: #0 /home/thisone/public_html/despatchbayservices.php(18): SoapClient->__soapCall('GetAvailableSer...', Array) #1 {main} thrown in /home/thisone/public_html/despatchbayservices.php on line 18
我肯定我在做一些非常愚蠢的事情,但我就是看不到它-任何帮助都非常感谢 使用了它-感谢不要惊慌,让我指向WDSL 正确/有效的代码为:
$params = array(
"Parcels" => array(
"ParcelType" => array(
"Weight" => 5,
"Length" => 5,
"Width" => 5,
"Height"=> 5,
)
),
"RecipientAddress" => array(
"RecipientName" => "Joe Bloggs",
"RecipientAddress" => array(
"CompanyName" => "My Company",
"Street" => "123 Any Street",
"Locality" => "Anywhere",
"TownCity" => "Any Town",
"County" => "Somewhere",
"PostalCode" => "TS23 4EA",
"CountryCode" => "GB",
)
),
"CollectionDate" => "2019-11-11",
);
// Invoke WS method (Function1) with the request params
$response = $client->__soapCall("GetAvailableServices", array($params));
第一个片段,但不是在数组中包装参数:
$response=$client->\uu soapCall(“GetAvailableServices”,$params)代码>您正在使用的web服务是否提供WSDL?这应该会向您展示它所支持的请求的正确格式!对不起,我昨天没有看到你的答复。当超过两个人发表评论时,当有人回复时不会通知你,除非他们@you。很高兴你弄明白了!我想不到RecipientAddress中需要一个RecipientAddress.:-)顺便说一下,如果您使用WSDL构建soap客户机,我认为您可以直接调用其方法,如$client->GetAvailableServices
,如果我没记错的话。