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;
Related
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'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
This is my WSDL XML: (Generated with SoapUI)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://soap.test.com/">
<soapenv:Header/>
<soapenv:Body>
<ser:myMethod>
<user>
<id>?</id>
<name>?</name>
</user>
<code>?</code>
</ser:myMethod>
</soapenv:Body>
</soapenv:Envelope>
And my PHP code to consume the "myMethod" method:
$opts = array(
'location' => 'http://example.com/myServices?WSDL',
'uri' => 'http://soap.test.com'
);
$client = new SOAPClient(null, $opts);
$res = $client->__soapCall('myMethod', array(
"id" => "123",
"name" => "Sam"
));
var_dump($res);
And I get the Cannot find dispatch method for {http://soap.test.com} myMethod error.
I've tested the SOAP with SoupUI and it has responsed correctly.
What is wrong here?
i wanna create soap request as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.cisco.com/AXL/API/10.0">
<soapenv:Header/>
<soapenv:Body>
<ns:updateUser sequence="?">
<!--You have a CHOICE of the next 2 items at this level-->
<uuid>{74932749237942794729473927493829}</uuid>
<userid>?</userid>
<associatedGroups>
<!--Zero or more repetitions:-->
<userGroup>
<name>Standard CTI Enabled</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CTI Enabled</userRole>
</userRoles>
</userGroup>
<userGroup>
<name>Standard CCM End Users</name>
<!--Optional:-->
<userRoles>
<!--Zero or more repetitions:-->
<userRole>Standard CCM End Users</userRole>
</userRoles>
</userGroup>
</associatedGroups>
</ns:updateUser>
</soapenv:Body>
</soapenv:Envelope>
I have this as my code so far:
$userId = "example#mydomain.com";
$retAccessWebex["UserUuid"] = "{74932749237942794729473927493829}"; //sample userUuid
$userGroup = array();
$userRoleCTI = array("Standard CTI Enabled");
$userGroup[] = array(
"name" => "Standard CTI Enabled",
"userRoles" => array(
"userRole" => $userRoleCTI,
)
);
$userRoleCCM = array("Standard CCM End Users");
$userGroup[] = array(
"name" => "Standard CCM End Users",
"userRoles" => array(
"userRole" => $userRoleCCM,
)
);
$param = array(
"uuid" => $retAccessWebex["UserUuid"],
"userid" => $userId,
"associatedGroups" => array(
array(
"userGroup" => $userGroup,
)
)
);
$mywsdl = "pathToSchemaWsdl/AXLAPI.wsdl";
$wsdl = "https://127.0.0.1:8443/axl/";
$client = new SoapClient($mywsdl,
array('trace' => true,
'exceptions' => true,
'location' => $wsdl,
'login' => 'administrator',
'password' => 'mtp455w0rd',
));
$response = $client->updateUser($param);
however, when executing, I get this error message:
Fatal error: Uncaught SoapFault exception: [Sender] SOAP-ERROR:
Encoding: object has no 'name' property
try to see what is in request
echo $client->__getLastRequestHeaders();
echo $client->__getLastRequest();
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";
}