Reputation: 191
I'm trying to create proper wsdl based soap request but with no success, here is example of what I need: soap.xml:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthMember xmlns="http://tempuri.org/">
<somefield>string</somefield>
</AuthMember>
</soap:Header>
<soap:Body>
<AuthenticateMember xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
My result is: soap.xml:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://schemas.xmlsoap.org/ws/2002/07/utility">
<SOAP-ENV:Header>
<ns2:AuthMember>
<somefield>somefieldvalue</somefield>
</ns2:AuthMember>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:AuthenticateMember/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
this is my php code:
class SoapHeaderAuthMember
{
public $somefield;
public function __construct($somefield)
{
$this->somefield = $somefield;
}
}
$client = new SoapClient( 'https://www.somepage.com/service.asmx?WSDL',
array("exceptions"=>0, "trace" => 1 )
);
$authMember = new SoapHeaderAuthMember('somefieldvalue');
$soapHeaders[] = new SoapHeader('http://schemas.xmlsoap.org/ws/2002/07/utility', 'AuthMember', $authMember);
$client->__setSoapHeaders($soapHeaders);
$client->__soapCall('AuthenticateMember',array());
see,
1.it generates SOAP-ENV:Envelope instead of SOAP-ENV:Envelope
2.in header: I have ns2:AuthMember instead of AuthMember
3.in body I have ns1:AuthenticateMember instead of AuthenticateMember xmlns="http://tempuri.org/"
How can I get proper xml ? I've looked through php functions manuals and cannot find the answer, googling did not give me success results for my case.
Could you please help ?
Upvotes: 0
Views: 1972
Reputation: 864
The result that has been generated is what has been requested in the code, but an explanation of some attributes of namespaces is in order:
Each of the tags in an XML document has a fully-qualified form which is defined by the namespace and the tag name (even if it is in the 'default' namespace with no explicit namespace declaration). The fully-qualified version is typically written as {namespace}tag. By resolving the fully-qualified name it is possible to determine whether the representation of two elements is the same.
Namespaces are associated with elements in multiple ways including explicit namespace inclusion with the element
Example:
<AuthMember xmlns="http://tempuri.org/">
resolving to fully-qualified name {http://tempuri.org/}AuthMember
and via namespace-associated prefix
Example:
<... xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
resolving to {http://schemas.xmlsoap.org/soap/envelope/}Header
The prefix is in scope for the element in which the prefix was declared and any contained elements. The actual prefix used is not important (soap, SOAP-ENV or randomprefix could be used for the http://schemas.xmlsoap.org/soap/envelope/ namespace), although good practice is to use something meaningful.
Given that, the fully-qualified elements in the 'desired' and 'actual' documents are almost the same, the anomaly being the header element AuthMember. In your desired you indicate a namespace of http://tempuri.org/ for a fully-qualified {http://tempuri.org/}AuthMember. In the actual the prefix association results in a fully-qualified {http://schemas.xmlsoap.org/ws/2002/07/utility}AuthMember.
This is the result of the SoapHeader instantiation specifying the ...utility namespace for AuthMember. Changing that statement in your code to use the http://tempuri.org/ namespace should result in the actual document matching the desired.
Upvotes: 1