我有这个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" } }
documentation表示输入XML应如下所示:
<CustomerSearch>
<AuthorID></AuthorID>
<UserID></UserID>
<UserPassword></UserPassword>
<SearchField></SearchField>
<SearchField></SearchField>
<!-- ...additional SearchField elements -->
</CustomerSearch>
我是Soap的新手,我试过搞乱(传入原始的,输出的XML),似乎无法让它工作。任何有关我可能做错的见解都将不胜感激。
答案 0 :(得分:10)
我认为您需要更多地了解文档(关于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 example with ANY_XML
)。
答案 1 :(得分:0)
尝试传递$client->CustomerSearch($CustomerSearch);
或传递字符串