php 如何定义 SoapVar 命名空间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10848269/
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
How to define a SoapVar namespace?
提问by rickyduck
I need to have this node in my SOAP Request (using 1.1):
我需要在我的 SOAP 请求中有这个节点(使用 1.1):
<CredentialsHeader xmlns="http://www.url.com/Services/P24ListingService11"
<EMail>[email protected]</EMail>
<Password>password</Password>
</CredentialsHeader>
So I have the following PHP:
所以我有以下PHP:
$client = new SoapClient("https://exdev.www.example.com/Services/example.asmx?WSDL",
array(
"trace" => 1,
"exceptions" => 0,
"cache_wsdl" => 0,
'soap_version' => SOAP_1_1
)
);
$CredentialObject = new SoapVar(array('EMail' => '[email protected]', 'Password' => 'password'), SOAP_ENC_OBJECT);
Which generates:
产生:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com/Services/Example">
<SOAP-ENV:Header>
<ns1:CredentialsHeader>
<EMail>[email protected]</EMail>
<Password>password</Password>
</ns1:CredentialsHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:EchoAuthenticated/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
All I need to do is prevent it using ns1and actually define the xmlnsin the node like so:
我需要做的就是阻止它使用ns1并实际xmlns在节点中定义 ,如下所示:
<CredentialsHeader xmlns="http://www.example.com/Services/Example">
<EMail>[email protected]</EMail>
<Password>password</Password>
</CredentialsHeader>
I have tested that in Firefox Poster and know for a fact that change fixes the problem.
我已经在 Firefox Poster 中进行了测试,并且知道更改可以解决问题的事实。
采纳答案by Umesh Chavan
$CredentialObjectXML = '<CredentialsHeader xmlns="http://www.example.com/Services/Example">
<EMail>'.$UserName.'</EMail>
<Password>'.$Password.'</Password>
</CredentialsHeader>';
$CredentialObject = new SoapVar($CredentialObjectXML,XSD_ANYXML);
This way you can directly use the XML with Type XSD_ANYXML.
这样您就可以直接使用 XSD_ANYXML 类型的 XML。
Hope this will resolve your problem.
希望这能解决您的问题。
回答by gokturk
http://www.php.net/manual/tr/soapvar.soapvar.php
http://www.php.net/manual/tr/soapvar.soapvar.php
Parameter "node_namespace" is what you've been looking for i guess.
我猜参数“node_namespace”就是你一直在寻找的。
回答by Bao-Long Nguyen-Trong
I had the same problem and found out that if you map a dummy class to the credential complex type from your WSDL, PHP will output something like:
我遇到了同样的问题,并发现如果将虚拟类映射到 WSDL 中的凭证复杂类型,PHP 将输出如下内容:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com/Services/Example">
<SOAP-ENV:Header>
<ns1:CredentialsHeader>
<ns1:EMail>[email protected]</ns1:EMail>
<ns1:Password>password</ns1:Password>
</ns1:CredentialsHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:EchoAuthenticated/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is not exactly what was requested but although more verbose, it is equivalent.
这不是所要求的,但虽然更冗长,但它是等效的。
The code goes like this:
代码是这样的:
$client = new SoapClient("https://exdev.www.example.com/Services/example.asmx?WSDL",
array(
"trace" => 1,
"exceptions" => 0,
"cache_wsdl" => 0,
"soap_version" => SOAP_1_1,
"classmap" => array(
'credential_complex_type' => 'CredentialObject',
),
)
);
class CredentialObject {}
$credentialObject = new CredentialObject();
$credentialObject->Email = '[email protected]';
$credentialObject->Password = 'password';

