使用 SoapClient 将 XML 输入发送到 WSDL [英] Sending XML input to WSDL using SoapClient

查看:39
本文介绍了使用 SoapClient 将 XML 输入发送到 WSDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我正在尝试使用 SoapClient 向 CustomerSearch<发送请求/a> 方法.

I am trying to use SoapClient to send a request to the CustomerSearch method.

我使用的代码如下:

$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 异常:

When I run the code, I get the following PHP exception:

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

我也为 XML 尝试过这个:

I have also tried this for the 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):

Which gives me the following results (from a print_r):

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

文档 说输入 XML应该看起来像这样:

The documentation says that the input XML should look something like this:

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

我对 Soap 还很陌生,我试过搞乱(传入原始的、输入的 XML),但似乎无法让它发挥作用.如果您对我可能做错的事情有任何见解,我们将不胜感激.

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.

推荐答案

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

I think you need to look more into the documentation (with regards to the any parameter). But your request should be something like this:

$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).

EDIT: This is how I've done it in similar project. It may not be best practice. SoapVar might be the better way to do it (SoapVoar example with ANY_XML).

这篇关于使用 SoapClient 将 XML 输入发送到 WSDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆