我试图用PHP创建这个输出:<?xml version="1.0" encoding="UTF-8"?>
123
PASSword
user@company.com
NG42DJ
这在Python中相当简单,我使用的类(suds)只读取wsdl文件,并正确使用名称空间:
^{pr2}$
不需要引用与名称空间相关的任何内容,它只需读取wsdl文件并进行计算即可。正如您在上面的原始XML中看到的,变量有名称空间,并在需要时继承,还请注意,主体位于ns1名称空间中。在
我在PHP中最接近的是使用WSDL-to-PHP转换器,它基于文件中的函数生成大量的类,但这样做似乎失去了所有名称空间的意义。到目前为止,我看到的唯一方法是修改生成的类文件,如下所示:// some code omitted...
use SoapVar; // added by me
// this is declared in AddressMatchingService namespace
class Credentials
{
public $AgentID = null;
public $Username = null;
public $Password = null;
public function __construct($AgentID, $Username, $Password)
{
//$this->AgentID = $AgentID;
$this->AgentID = new SoapVar($AgentID, null, null, null, null, "http://webservices.company.co.uk/ServiceBase/");
//$this->Username = $Username;
$this->Username = new SoapVar($Username, null, null, null, null, "http://webservices.company.co.uk/ServiceBase/");
//$this->Password = $Password;
$this->Password = new SoapVar($Password, null, null, null, null, "http://webservices.company.co.uk/ServiceBase/");
}
}
$wsdl = base_path() . '/resources/wsdl/AddressMatchingService.wsdl';
$soap = new SoapClient($wsdl, array('trace'=>1));
$creds = new AddressMatchingService\Credentials('123', 'user@company.com','PASSword');
$address = new AddressMatchingService\Address('NG42DJ');
$request = array('request' => $request);
$request = new SoapVar($request, SOAP_ENC_OBJECT);
$response = $soap->__soapCall("GetAvailableAddresses", array('request' => $request));
这让我很接近:<?xml version="1.0" encoding="UTF-8"?>
NG42DJ
123
PASSword
user@company.co.uk
但如果在Python中这么简单,我想我可能做错了什么。在每个类中指定名称空间似乎很痛苦,我仍然不知道是否可以将主体的名称空间从“SOAP-ENV”更改为ns1。如果可以避免的话,我希望避免手工编写XML,因为WSDL中有太多的函数和变量,我希望它能像pythonsuds库那样高效地工作!在