I use SOAP as a method to communicate with the asp.net service. The problem is that I need to pass the XML without ns1: .
This is the request I send now:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ex.ex.com/">
<SOAP-ENV:Body>
<ns1:GetInfoFromSending>
<ns1:Key>XXX</ns1:Key>
<ns1:ObjectID>2468</ns1:ObjectID>
</ns1:GetInfoFromSending>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But the format of the request needed is this:
<?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:Body>
<GetInfoFromSendingList xmlns="http://ex.ex.com/">
<Key>string</Key>
<ObjectID>int</ObjectID>
</GetInfoFromSendingList>
</soap:Body>
</soap:Envelope>
I tried using MSSoapClient from PHP Manual but doesn't seem to work
try {
$soap = new MSSoapClient($wsdl, $options);
var_dump($soap);
$data = $soap->__soapCall('GetInfoFromSending', array('parameters'=>$params));
var_dump($soap);
}
catch(Exception $e) {
die($e->getMessage());
}
What is $namespace = "http://tempuri.com"; in MSSoapClient
Resolved by using the default __soapCall from SOAP.
I want to create an XML document (with namesapace) as per structured below, using PHP. My objective is to create xml which will be pushed to server (using curl).
<?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:Body>
<InsertData xmlns="http://tempuri.org/">
<userName>string</userName>
<password>string</password>
<costCenterCode>string</costCenterCode>
<consigneeName>string</consigneeName>
<consigneeAddress>string</consigneeAddress>
<consigneeMobNo>string</consigneeMobNo>
<consigneeEmail>string</consigneeEmail>
<originCityName>string</originCityName>
<destinationCityName>string</destinationCityName>
<pieces>string</pieces>
<weight>string</weight>
<codAmount>decimal</codAmount>
<custRefNo>string</custRefNo>
<productDetails>string</productDetails>
<fragile>string</fragile>
<services>string</services>
<remarks>string</remarks>
<insuranceValue>string</insuranceValue>
</InsertData>
</soap:Body>
</soap:Envelope>
Here is my code to create xml, but issue is that it does not add namespace with child and Web service server is giving me error as it is not structured as per their xml reference.
$xml = new SimpleXMLElement('<?xml version = "1.0" ?><Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" />');
$body = $xml->addChild("Body");
$tcsAPI = $body->addChild('InsertData');
$tcsAPI->addChild('userName', "xxxxxx");
$tcsAPI->addChild('password', "xxxxxx");
$tcsAPI->addChild('costCenterCode', "CC001");
$tcsAPI->addChild('consigneeName', "MagDev");
$tcsAPI->addChild('consigneeAddress', "Address");
$tcsAPI->addChild('consigneeMobNo', "00000000");
$tcsAPI->addChild('consigneeEmail', "email#some.com");
$tcsAPI->addChild('originCityName', "ORG");
$tcsAPI->addChild('destinationCityName', "DEST");
$tcsAPI->addChild('pieces', "1");
$tcsAPI->addChild('weight', "1");
$tcsAPI->addChild('codAmount', "0");
$tcsAPI->addChild('custRefNo', "WEBT");
$tcsAPI->addChild('productDetails', "Test Product");
$tcsAPI->addChild('fragile', "0");
$tcsAPI->addChild('services', "0");
$tcsAPI->addChild('remarks', "Testing API services");
$tcsAPI->addChild('insuranceValue', "0");
Thanks
The methods have an additional argument that allows you to specify the namespace. This will add the namespace definitions (the xmlns attributes) as needed.
$xmlns = [
'soap' => 'http://www.w3.org/2003/05/soap-envelope',
't' => 'http://tempuri.org/'
];
$xml = new SimpleXMLElement(
'<?xml version = "1.0" ?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" />'
);
$body = $xml->addChild("soap:Body", null, $xmlns['soap']);
$tcsAPI = $body->addChild('InsertData', null, $xmlns['t']);
//...
echo $xml->asXml();
You can add the namespace definitions manually like attributes. But this is only needed to avoid multiple definitions on descendants. If an ancestor already defines the namespace the descendant doesn't need to do this any more.
Be aware that attributes are only in a namespace if they have an prefix, default namespaces are only valid for elements. Attributes without a prefix are always in the 'empty' namespace.
$tcsAPI->addAttribute('xmlns', 'http://tempuri.org/');
I'm trying to send an SOAP request.
My request looks like this
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="someurl">
<SOAP-ENV:Body>
<RequestIndBApplication>
But my customer told me it has to look like this
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<process xmlns="someurl">
<RequestIndBApplication>
I'm using an WSDL file i got from my customer. But i don't know how i can change the soap tag. is there a way to do this?
Here is my php code
$client = new SoapClient('urlofwsdlfile',array('trace' => true, 'exceptions' => true)); $params = new \SoapVar($xmlstr), \XSD_ANYXML);
$result = $client->__SoapCall('process', array($params));
$xmlstr contains the data as xml
I have an std object :
$args = new stdClass();
$args->userName = 'username';
$args->password = 'password';
$args->criteria->customer->customerId = '0002003';
I want create SoapRequest XML :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="wsclient.dms.tecsys.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<mns1:search xmlns:mns1="wsclient.dms.tecsys.com">
<arg0>
<userName>username</userName>
<password>password</password>
<criteria>
<customer>
<customerId>0002003</customerId>
</customer>
</criteria>
</arg0>
</mns1:search>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But i can't find solution. Can any one help me.
Regards
By using the SoapClient class you can create a soap request easily
Take a look at this
SoapClient: __doRequest — Which performs a SOAP request
I want to imitate the following SOAP request using Zend Framework but I don't understand the '__MethodSignature' part in header. Could someone please explain this?
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<h3:__MethodSignature xsi:type="SOAP-ENC:methodSignature"
xmlns:h3="http://schemas.microsoft.com/clr/soap/messageProperties"
SOAP-ENC:root="1">
xsd:string
</h3:__MethodSignature>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<i4:ReturnDataset id="ref-1"
xmlns:i4="http://schemas.microsoft.com/clr/nsassem/Interface.IReturnDataSet/Interface">
<tName id="ref-5">BU</tName>
</i4:ReturnDataset>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
When I call this ReturnDataSet function like this:
$client = new Zend_Soap_Client($wsdl_url, array('soap_version' => SOAP_1_1));
$tName = "BU";
$result = $client->ReturnDataset($tName);
Server throws an error. I think this header part is playing some role?
Try setting the MethodSignature or __MethodSignature SOAP header. With the normal PHP SOAP client, you do this as follows:
$client->__setSoapHeaders(new SoapHeader(
'http://schemas.microsoft.com/clr/soap/messageProperties',
'__MethodSignature',
'xsd:string'
));