7

我有这个 WSDL:https ://secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL

我正在尝试使用 SoapClient 向CustomerSearch方法发送请求。

我正在使用的代码如下:

$url = 'https://secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL';
$client = new SoapClient($url);

$CustomerSearch = array(
    'AuthorID' => $authorID,
    'UserID' => $userID,
    'UserPassword' => $userPassword,
    'Email' => $customerEmail 
);

$xml = array('CustomerSearch' => $CustomerSearch);

$result = $client->CustomerSearch(array('xml' => $xml));

当我运行代码时,我得到以下 PHP 异常:

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'any' property

我也为 XML 尝试过这个:

$xml = "
<?xml version=\"1.0\" encoding=\"utf-8\"?> 
<CustomerSearch>
    <AuthorID>$authorID</AuthorID>
    <UserID>$userID</UserID>
    <UserPassword>$userPassword</UserPassword>
    <Email>$customerEmail</Email>
</CustomerSearch>
";

这给了我以下结果(来自 print_r):

object(stdClass)#4 (1) { ["CustomerSearchResult"]=> object(stdClass)#5 (1) { ["any"]=> string(108) "-2Invalid Xml Document" } }

文档说输入 XML 应该是这样的:

<CustomerSearch>
<AuthorID></AuthorID>
<UserID></UserID>
<UserPassword></UserPassword>
<SearchField></SearchField>
<SearchField></SearchField>
<!-- ...additional SearchField elements -->
</CustomerSearch> 

我对 Soap 还很陌生,我尝试过搞乱(传入原始的、输入的 XML),但似乎无法让它工作。任何关于我可能做错了什么的见解将不胜感激。

4

2 回答 2

12

我认为您需要更多地查看文档(关于any参数)。但是您的请求应该是这样的:

$url = 'https://secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL';
$client = new SoapClient($url);

$xmlr = new SimpleXMLElement("<CustomerSearch></CustomerSearch>");
$xmlr->addChild('AuthorID', $authorID);
$xmlr->addChild('UserID', $userID);
$xmlr->addChild('UserPassword', $userPassword);
$xmlr->addChild('Email', $customerEmail);

$params = new stdClass();
$params->xml = $xmlr->asXML();

$result = $client->CustomerSearchS($params);

编辑:这就是我在类似项目中所做的。这可能不是最佳实践。SoapVar可能是更好的方法(SoapVoar示例ANY_XML)。

于 2013-05-17T06:23:33.267 回答
0

尝试传递$client->CustomerSearch($CustomerSearch);或传递一个字符串

于 2013-05-16T19:52:15.640 回答