php 使用 SoapClient 将 XML 输入发送到 WSDL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16595789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending XML input to WSDL using SoapClient
提问by Axel
I have this WSDL: https://secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL
我有这个 WSDL:https: //secure.softwarekey.com/solo/webservices/XmlCustomerService.asmx?WSDL
I am trying to use SoapClient to send a request to the CustomerSearchmethod.
我正在尝试使用 SoapClient 向CustomerSearch方法发送请求。
The code I'm using is as follows:
我使用的代码如下:
$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));
When I run the code, I get the following PHP exception:
当我运行代码时,我收到以下 PHP 异常:
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object has no 'any' property
I have also tried this for the XML:
我也为 XML 尝试过这个:
$xml = "
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<CustomerSearch>
<AuthorID>$authorID</AuthorID>
<UserID>$userID</UserID>
<UserPassword>$userPassword</UserPassword>
<Email>$customerEmail</Email>
</CustomerSearch>
";
Which gives me the following results (from a print_r):
这给了我以下结果(来自print_r):
object(stdClass)#4 (1) { ["CustomerSearchResult"]=> object(stdClass)#5 (1) { ["any"]=> string(108) "-2Invalid Xml Document" } }
The documentationsays that the input XML should look something like this:
该文件说,XML输入应该是这个样子:
<CustomerSearch>
<AuthorID></AuthorID>
<UserID></UserID>
<UserPassword></UserPassword>
<SearchField></SearchField>
<SearchField></SearchField>
<!-- ...additional SearchField elements -->
</CustomerSearch>
I'm fairly new to Soap and I've tried messing around (passing in raw, typed out XML), and can't seem to get this to work. Any insight on what I may be doing wrong would be greatly appreciated.
我对 Soap 还很陌生,我试过搞乱(传入原始的、输入的 XML),但似乎无法让它发挥作用。任何关于我可能做错了什么的见解将不胜感激。
回答by denormalizer
I think you need to look more into the documentation (with regards to the any
parameter). But your request should be something like this:
我认为您需要更多地查看文档(关于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);
EDIT: This is how I've done it in similar project. It may not be best practice. SoapVarmight be the better way to do it (SoapVoarexample with ANY_XML
).
编辑:这就是我在类似项目中所做的。这可能不是最佳实践。SoapVar可能是更好的方法(带有 的 SoapVoar示例ANY_XML
)。
回答by Rahul11
try passing $client->CustomerSearch($CustomerSearch);
or pass a string
尝试传递$client->CustomerSearch($CustomerSearch);
或传递一个字符串