I'm trying to make a soap request and having difficulties.
Here is my php:
<?php
$option=array('trace'=>1);
$soapClient = new SoapClient('http://www.domain.com/ws/AccountManagement.wsdl', $option);
$headers = array('LOGIN_ID' => 'user#user.com', 'LOGIN_PASSWORD' => 'mypassword');
$header = new SoapHeader('https://www.domain.com', 'AuthenticationDTO', $headers, false);
$soapClient->__setSoapHeaders($header); //or array($header)
$params = array(
'bureauName' => '',
'businessInformation' => array('address' => array('city' => 'SomeCity'), array('country' => 'US'), array('state' => 'MN'), array('street' => 'Some Address'), array('zipCode' => '33212')), array('businessName' => 'SomeBusinessName'),
'entityType' => '',
'listOfSimilars' => 'true',
);
try {
$result = $soapClient->__call("matchCompany", $params);
print_r($result);
} catch (SoapFault $fault) {
echo $fault->faultcode . "-" . $fault->faultstring;
echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
}
?>
It fails on $soapClient__call.
getLastRequest() produces this XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://com.dnbi.eai.service.AccountSEI" xmlns:ns2="http://dto.eai.dnbi.com">
<SOAP-ENV:Header>
<ns2:AuthenticationDTO>
<ns2:LOGIN_ID>user#user.com</ns2:LOGIN_ID>
<ns2:LOGIN_PASSWORD>mypassword</ns2:LOGIN_PASSWORD>
</ns2:AuthenticationDTO>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:matchCompany/>
<param1><item>
<key>address</key>
<value><item>
<key>city</key>
<value>SomeCity</value>
</item></value>
</item><item>
<key>0</key>
<value><item>
<key>country</key>
<value>US</value>
</item></value>
</item><item>
<key>1</key>
<value><item>
<key>state</key>
<value>MN</value>
</item></value>
</item><item>
<key>2</key>
<value><item>
<key>street</key>
<value>Some Address</value>
</item></value>
</item><item>
<key>3</key>
<value><item>
<key>zipCode</key>
<value>33212</value>
</item></value>
</item></param1>
<param2><item>
<key>businessName</key>
<value>SomeBusinessName</value>
</item></param2>
<param3></param3>
<param4>true</param4>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is not the correct XML output. I must be doing something wrong. Using soapUI I found that this is the correct XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dto="http://dto.eai.dnbi.com" xmlns:com="http://com.dnbi.eai.service.AccountSEI">
<soapenv:Header>
<dto:AuthenticationDTO>
<dto:LOGIN_ID>user#user.com</dto:LOGIN_ID>
<dto:LOGIN_PASSWORD>mypassword</dto:LOGIN_PASSWORD>
</dto:AuthenticationDTO>
</soapenv:Header>
<soapenv:Body>
<com:matchCompany>
<com:in0>
<!--Optional:-->
<dto:bureauName></dto:bureauName>
<!--Optional:-->
<dto:businessInformation>
<dto:address>
<!--Optional:-->
<dto:city>SomeCity</dto:city>
<dto:country>US</dto:country>
<dto:state>MN</dto:state>
<dto:street>Some Address</dto:street>
<!--Optional:-->
<dto:zipCode></dto:zipCode>
</dto:address>
<!--Optional:-->
<dto:businessName>SomeBusinessName</dto:businessName>
</dto:businessInformation>
<!--Optional:-->
<dto:entityNumber></dto:entityNumber>
<!--Optional:-->
<dto:entityType></dto:entityType>
<!--Optional:-->
<dto:listOfSimilars>true</dto:listOfSimilars>
</com:in0>
</com:matchCompany>
</soapenv:Body>
</soapenv:Envelope>
Can anybody help me produce the same XML that soapUI produced for me, but using PHP5's native Soap client?
Thanks
Try this code instead. Note how it uses anonymous objects to create the required hierarchy:
$options = array(
'trace' => 1
);
$soapClient = new SoapClient('http://www.domain.com/ws/AccountManagement.wsdl', $option);
$headers = array(
'LOGIN_ID' => 'user#user.com',
'LOGIN_PASSWORD' => 'mypassword'
);
$header = new SoapHeader('dto', 'AuthenticationDTO', $headers, false);
$soapClient->__setSoapHeaders($header);
$matchCompany->in0->bureauName = '';
$matchCompany->in0->businessInformation->address->city = 'SomeCity';
$matchCompany->in0->businessInformation->address->country = 'US';
$matchCompany->in0->businessInformation->address->state = 'MN';
$matchCompany->in0->businessInformation->address->street = 'Some Address';
$matchCompany->in0->businessInformation->address->zipCode = '33212';
$matchCompany->in0->businessInformation->businessName = 'SomeBusinessName';
$matchCompany->in0->entityType = '';
$matchCompany->in0->listOfSimilars = true;
try
{
$result = $soapClient->matchCompany($matchCompany);
print_r($result);
}
catch(SoapFault $fault)
{
echo $fault->faultcode . "-" . $fault->faultstring;
echo "REQUEST:\n" . htmlentities($soapClient->__getLastRequest()) . "\n";
}
Related
I need to make following custom SOAP HEADER in PHP for a soap request call.
<?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>
<AuthHeader xmlns="http://www.example.com/">
<Username></Username>
<Password></Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<ProductInfo xmlns="http://www.example.com/">
<myXMLNode>xml</myXMLNode>
</ProductInfo>
</soap:Body>
</soap:Envelope>
For this, I have created following PHP code:
try {
$soapHeader = new SoapHeader('http://www.example.com/', 'AuthHeader', ['Username' => '', 'Password' => '']);
$soapClient = new SoapClient('http://192.168.1.1/examplewebservices/exampleweb.asmx?WSDL', ['cache_wsdl' => WSDL_CACHE_NONE, 'trace' => 1]);
$soapClient->__setSoapHeaders($soapHeader);
$soapBody = [
'ProductInfo' => [
'xmlns' => 'http://www.example.com/',
'myXMLNode' => [
'_' => 'xml',
]
]
];
$soapResponse = $soapClient->ProductInfo($soapBody);
echo "REQUEST:\n" . $soapClient->__getLastRequest() . "\n";
} catch(Exception $e) {
echo 'Message: ' . $e->getMessage();
}
But above generating this kind of XML, with ns1 as prefix, which I don't need:
<?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/">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:Username></ns1:Username>
<ns1:Password></ns1:Password>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:ProductInfo/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Can anyone please help to fix this!
U could use SoapVar. Try like:
//....
$authHeaders[] = '<Username>'.$auth['Username'].'</Username>';
$authHeaders[] = '<Password>'.$auth['Password'].'</Password>';
$autStr = implode('',$authHeaders);
$authSoapVar = new \SoapVar( $autStr, XSD_ANYXML, NULL, NULL, NULL, NULL );
$headers = new \SoapHeader('http://www.example.com/','AuthHeader',$authSoapVar);
//...
I am trying to generate the params for below XML, but its not working. I doubt how I convert this to PHP array in $params, any help is appreciated
<soapenv:Header/>
<soapenv:Body>
<tem:GetServicesforPincode>
<!--Optional:-->
<tem:pinCode>695587</tem:pinCode>
<!--Optional:-->
<tem:profile>
<!--Optional:-->
<sapi:Api_type>S</sapi:Api_type>
<!--Optional:-->
<sapi:Customercode>099960</sapi:Customercode>
<!--Optional:-->
<sapi:LicenceKey>9b40edffc20ce2e6fc1462a30fc48181</sapi:LicenceKey>
<!--Optional:-->
<sapi:LoginID>BLR00132</sapi:LoginID>
<!--Optional:-->
</tem:profile>
</tem:GetServicesforPincode>
</soapenv:Body>
</soapenv:Envelope>
I tried like this:
$params = array(
'pinCode' => array (
"695587",
),
// 'pinCode' => '695587',
'Profile' => array(
'Api_type' => 'S',
'LicenceKey' => '9b40edffc20ce2e6fc1462a30fc48181',
'LoginID' => 'BLR00132',
'Version' => '1.3'
)
);
$wsdl = 'http://netconnect.bluedart.com/Ver1.8/Demo/ShippingAPI/Finder/ServiceFinderQuery.svc?wsdl';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
$soap = new SoapClient($wsdl);
$data = $soap->GetServicesforPincode($params);
}
catch(Exception $e) {
die($e->getMessage());
}
print_r($data);
die;
I have hml which works fine in SOAPUI:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"
xmlns:wssc="http://schemas.datacontract.org/2004/07/WSSC.V4.DMS.EKV.WssDocsService">
<soapenv:Header/>
<soapenv:Body>
<tem:CreateDocument>
<!--Optional:-->
<tem:parameters>
<!--Optional:-->
<!--Optional:-->
<wssc:DocType>01</wssc:DocType>
<!--Optional:-->
<!--Optional:-->
<!--Optional:-->
<wssc:FieldValues>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>value1</wssc:Name>
<!--Optional:-->
<wssc:Value>email#email.email</wssc:Value>
</wssc:BaseDocumentField>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>content</wssc:Name>
<!--Optional:-->
<wssc:Value>just text</wssc:Value>
</wssc:BaseDocumentField>
<wssc:BaseDocumentField xsi:type="wssc:DocumentField"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--Optional:-->
<wssc:Name>name</wssc:Name>
<!--Optional:-->
<wssc:Value>number</wssc:Value>
</wssc:BaseDocumentField>
</wssc:FieldValues>
<wssc:UserMail>email#email.email</wssc:UserMail>
</tem:parameters>
</tem:CreateDocument>
</soapenv:Body>
</soapenv:Envelope>
I need to create an array to repeat its structure.
Now I have such an array, but it does not work to the full:
<?php
$params = array(
'parameters' => array(
'DocType' => '01',
'UserMail' => 'email#email.email',
'FieldValues' => array(
'BaseDocumentField' => array(
'name' => 'something',
'value' => 'something',
),
'BaseDocumentField' => array(
'name' => 'something',
'value' => 'something',
),
),
)
);
$client = new SoapClient("http://servicename?wsdl", array("trace" => 1, "exceptions" => 0, "login" => $login, "password" => $password));
$result = $client->CreateDocument($params);
try {
$request = $client->CreateDocument($params);
$last_request = $client->__getLastRequest();
} catch (SoapFault $exception) {
$last_request = $client->__getLastRequest();
}
var_dump($last_request);
?>
The function __getLastRequest produces the following result:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.datacontract.org/2004/07/WSSC.V4.DMS.EKV.WssDocsService"
xmlns:ns2="http://tempuri.org/">
<SOAP-ENV:Body>
<ns2:CreateDocument>
<ns2:parameters>
<ns1:DocType>01</ns1:DocType>
<ns1:FieldValues>
<ns1:BaseDocumentField/>
</ns1:FieldValues>
<ns1:UserMail>email#email.email</ns1:UserMail>
</ns2:parameters>
</ns2:CreateDocument>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I do not understand how to properly construct an array so that the section is displayed correctly.
how can I do it?
If you're working with a complex WSDL, you should definitively use a WSDL to php generator such as the PackageGenerator project. It'll generate all the classes required to construct the request then to receive the response. Using a good IDE such as Eclipse or PhpStorm, you'll have the full auto-completion wich will ease you the request construction without having to wonder how to do it.
I'm new to using SOAP and PHP, and I need to create a request exactly like this using PHP SoapClient class:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ent="http://enterprise.000.000.com/Infrastructure/EnterpriseContext"
xmlns:ns="http://000.000.com/000/service/000/intf/1">
<soap:Header>
<ent:enterpriseContext>
<ent:contextInfo>
<ent:ProcessContextId>000K121300223393915419638486638404</ent:ProcessContextId>
<ent:businessContextId>CO</ent:businessContextId>
<ent:applicationContextId>3</ent:applicationContextId>
</ent:contextInfo>
<ent:requestOriginator>
<ent:requesterCode>000</ent:requesterCode>
<ent:machineIPAddress>0.0.0.0</ent:machineIPAddress>
<ent:userPrincipleName>000</ent:userPrincipleName>
<ent:requestedTimestamp>2015-10-01T05:53:04</ent:requestedTimestamp>
<ent:channelId>1</ent:channelId>
</ent:requestOriginator>
</ent:enterpriseContext>
</soap:Header>
<soap:Body>
<ns:InitiatePaymentDetails>
<InitiatePaymentDetailsRequest>
<transactionAmount>35</transactionAmount>
<olpIdAlias>000_uat_uat1</olpIdAlias>
<merchantRefNum>7999</merchantRefNum>
<!--1 or more repetitions:-->
<merchants>
<merchantId>1003</merchantId>
<merchantRefNum>7999</merchantRefNum>
<paymentAmount>35</paymentAmount>
<paymentCurrency>SAR</paymentCurrency>
<merchantType>1</merchantType>
</merchants>
<merchantId>1003</merchantId>
</InitiatePaymentDetailsRequest>
</ns:InitiatePaymentDetails>
</soap:Body>
</soap:Envelope>
How can I achieve that?
I just managed to solve the problem
Although the code I used didn't produce an identical XML request, but It fulfills the web service requirements. I put the answer here for any one with a similar problem.
$wsdl = 'https://000.000.com/000abpayproc-ws/000PaymentManager.wsdl';
$client = new SoapClient($wsdl, array('trace' => 1));
$unique_id = mt_rand(100000, 999999);
$timestamp = time();
$ref_number = mt_rand(10000000, 99999999);
$headerbody = array(
'contextInfo' => array(
'ProcessContextId' => '000'.$unique_id.$timestamp,
'businessContextId' => 'CO',
'applicationContextId' => 3
),
'requestOriginator' => array(
'requesterCode' => '000',
'machineIPAddress' => '00.00.00.00',
'userPrincipleName' => '000',
'requestedTimestamp' => '2015-10-01T05:53:04',
'channelId' => 1
),
);
$ns = 'http://000.000.com/000/service/000/intf/1';
$header = new SOAPHeader($ns, 'enterpriseContext', $headerbody);
$ent = 'http://000.000.000.com/Infrastructure/EnterpriseContext';
$header2 = new SOAPHeader($ent, 'enterpriseContext', $headerbody);
$parm = array(
'InitiatePaymentDetailsRequest' =>
array(
'transactionAmount' => 35,
'olpIdAlias' => '000',
'merchantRefNum' => $ref_number,
'merchants' => array(
'merchantId' => 1003,
'merchantRefNum' => 7999,
'paymentAmount' => 35,
'paymentCurrency' => 'SAR',
'merchantType' => 1,
),
'merchantId' => 1003
)
);
try {
$resp = $client->__soapCall('InitiatePaymentDetails', array($parm), array(), array($header, $header2));
echo 'REQUEST:<br />';
var_dump($client->__getLastRequest());
echo '<br />';
echo 'RESPONSE:<br />';
dd($resp);
} catch (SoapFault $ex) {
echo 'REQUEST:<br />';
$client->__getLastRequest();
echo '<br />';
echo 'RESPONSE:<br />';
echo $ex->getMessage();
}
The resulting request was as follows:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://000.000.com/000/service/000/intf/1" xmlns:ns2="http://enterprise.000.000.com/Infrastructure/EnterpriseContext">
<SOAP-ENV:Header>
<ns1:enterpriseContext>
<item>
<key>contextInfo</key>
<value>
<item>
<key>ProcessContextId</key>
<value>0004331921464611756</value>
</item>
<item>
<key>businessContextId</key>
<value>CO</value>
</item>
<item>
<key>applicationContextId</key>
<value>3</value>
</item>
</value>
</item>
<item>
<key>requestOriginator</key>
<value>
<item>
<key>requesterCode</key>
<value>000</value>
</item>
<item>
<key>machineIPAddress</key>
<value>00.00.00.00</value>
</item>
<item>
<key>userPrincipleName</key>
<value>000</value>
</item>
<item>
<key>requestedTimestamp</key>
<value>2015-10-01T05:53:04</value>
</item>
<item>
<key>channelId</key>
<value>1</value>
</item>
</value>
</item>
</ns1:enterpriseContext>
<ns2:enterpriseContext>
<ns2:contextInfo>
<ns2:ProcessContextId>004331921464611756</ns2:ProcessContextId>
<ns2:businessContextId>CO</ns2:businessContextId>
<ns2:applicationContextId>3</ns2:applicationContextId>
</ns2:contextInfo>
<ns2:requestOriginator>
<ns2:requesterCode>000</ns2:requesterCode>
<ns2:machineIPAddress>00.00.00.00</ns2:machineIPAddress>
<ns2:userPrincipleName>000</ns2:userPrincipleName>
<ns2:requestedTimestamp>2015-10-01T05:53:04</ns2:requestedTimestamp>
<ns2:channelId>1</ns2:channelId>
</ns2:requestOriginator>
</ns2:enterpriseContext>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:InitiatePaymentDetails>
<InitiatePaymentDetailsRequest>
<transactionAmount>35</transactionAmount>
<olpIdAlias>000</olpIdAlias>
<merchantRefNum>51777161</merchantRefNum>
<merchants>
<merchantId>1003</merchantId>
<merchantRefNum>7999</merchantRefNum>
<paymentAmount>35</paymentAmount>
<paymentCurrency>SAR</paymentCurrency>
<merchantType>1</merchantType>
</merchants>
<merchantId>1003</merchantId>
</InitiatePaymentDetailsRequest>
</ns1:InitiatePaymentDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
i've got this XML and it works in soapUi
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="xxx" xmlns:data="xxx">
<soapenv:Header/>
<soapenv:Body>
<web:FindArticles>
<web:request>
<data:culture_id>de-DE</data:culture_id>
<data:vehicle_search_parameters>
<data:address>
<!--Optional:-->
<data:countries>
<!--Zero or more repetitions:-->
<data:country_id>D</data:country_id>
</data:countries>
<!--Optional:-->
</data:address>
<data:dealer_id>XXX</data:dealer_id>
<data:show_dealer_vehicles>true</data:show_dealer_vehicles>
</data:vehicle_search_parameters>
</web:request>
</web:FindArticles>
</soapenv:Body>
</soapenv:Envelope>
But I can not fugure out how to call it via PHP. I'm trying something like this, but get errors...
<?php
$wsdl = 'XXX';
$options = array(
'login' => 'XXX',
'password' => 'XXX',
'trace'=>true
);
$params = array(
'culture_id' => 'de-DE',
'country_id' => 'D',
'dealer_id' => 'XXX',
'show_dealer_vehicles' => true
);
try {
$soap = new SoapClient($wsdl, $options);
$data = $soap->FindArticles($params);
}
catch(Exception $e) {
die($e->getMessage());
}
var_dump($data);
die;
It looks, that there is some kind of nested functions - how have I call it via PHP? I've tried smth like $soap->FindArticles('request', $params), but it still does not work