PHP with soap client API inetegration is not working - php

I am new for handling soap API Request-Response, I need help to implement SMS code using SMS gateway API.
I am using PHP with curl request for send SMS through SMS Gateway API below is my code to send SMS to customer(s)
<?php
define("USERNAME","#username#");
define("PASSWORD","#password#");
$soapUrl = "soap_wsdl_url";
$xml_post_string = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:templateSMS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:ElbaridTNS" xmlns:ns3="namespace" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<ns3:AuthHeader>
<username>USERNAME</username>
<password>PASSWORD</password>
</ns3:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:templateSMS>
<Sms xsi:type="ns2:Sms"><phoneNumber xsi:type="xsd:string">phoneNumber</phoneNumber>
<message xsi:type="xsd:string">Hello User, this is test SMS message. We can successfully send SMS.</message>
<unicodeMessage xsi:type="xsd:string">test SMS</unicodeMessage>
<sms_type_id xsi:type="xsd:string">1</sms_type_id>
<notify xsi:type="xsd:string">0</notify>
<senderId xsi:type="xsd:string">SENDERID</senderId>
<priority xsi:type="xsd:string">2</priority>
<vbApp xsi:type="xsd:string">SoapRequest</vbApp>
<vbIdTime xsi:type="xsd:string">20161130101112</vbIdTime>
<destinationPort xsi:type="xsd:string">-1</destinationPort></Sms>
</ns1:templateSMS>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: templateSMS",
"Content-length: ".strlen($xml_post_string),
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
echo $response;
$response1 = str_replace("<soap:Body>","",$response);
$response2 = str_replace("</soap:Body>","",$response1);
$parser = simplexml_load_string($response2);
echo $parser['resultCode'];
echo "<pre>";
print_r($parser);
echo "</pre>";
curl_close($ch);
?>
I got this response on $parser['resultCode'] "Send Unicast Message". I don't know what is the meaning of this response. I did R&Ds on this issue since 2 days but not getting any success.
Can anyone help me to fix the above issue?

Support team gave me a request and response sample code that should pass in the xml format, below is the request, response sample structure
Request
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:templateSMS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:ElbaridTNS" xmlns:ns3="namespace" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<ns3:AuthHeader>
<username>username </username>
<password>password</password>
</ns3:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:templateSMS>
<Sms xsi:type="ns2:Sms"><phoneNumber xsi:type="xsd:string">xxxxxx</phoneNumber>
<message xsi:type="xsd:string">test SMS </message>
<unicodeMessage xsi:type="xsd:string">test SMS</unicodeMessage>
<sms_type_id xsi:type="xsd:string">1</sms_type_id>
<notify xsi:type="xsd:string">0</notify>
<senderId xsi:type="xsd:string">SenderId</senderId>
<priority xsi:type="xsd:string">2</priority>
<vbApp xsi:type="xsd:string">SoapRequest</vbApp>
<vbIdTime xsi:type="xsd:string">20161130101112</vbIdTime>
<destinationPort xsi:type="xsd:string">-1</destinationPort></Sms>
</ns1:templateSMS>
</SOAP-ENV:Body>
Response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:templateSMS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:templateSMSResponse>
<templateSMSResponse xsi:type="xsd:string">0#!#200#!#http://198.101.210.203/Soap/service/elbarid|http://212.98.137.180/Soap/service/elbarid#!#SenderId
</templateSMSResponse>
</ns1:templateSMSResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Related

Get a value from SOAP response from multiple xml data using PHP

This is the response of the soap request.
<?xml version="1.0" encoding="utf-8"?>
<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>
<GetConfigurationInfoResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://micros-hosting.com/EGateway/">
<configInfoResponse>
<OperationalResult>
<Success>true</Success>
<ErrorCode>Success</ErrorCode>
<ErrorMessage>Success</ErrorMessage>
</OperationalResult>
<ConfigInfoType>
<EConfigurationInfoType>MENUITEMDEFINITIONS</EConfigurationInfoType>
</ConfigInfoType>
**<MenuItemDefinitions><?xml version="1.0" encoding="utf-8"?><?micros-type Micros.PosCore.DataStore.DbRecords.DbMenuItemDefinition[], PosCore, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null?><ArrayOfDbMenuItemDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><DbMenuItemDefinition><NameOptions>0000000</NameOptions><MenuItemDefID>4055</MenuItemDefID><HierStrucID>25</HierStrucID><MenuItemMasterID>1570</MenuItemMasterID><SequenceNum>1</SequenceNum><Name1><StringNumberId>8507</StringNumberId><StringText>=Breakfast=</StringText></Name1><Name2><StringNumberId>8508</StringNumberId><StringText /></Name2><SluSort>0</SluSort><NluNumber>0</NluNumber><Tare>0</Tare><Surcharge>0</Surcharge><IconNumber>0</IconNumber><OptionBits>00000000</OptionBits><SpecialCount>0</SpecialCount><PrepTime>0</PrepTime><Name3><StringNumberId>0</StringNumberId><StringText /></Name3><LongDescriptor><StringNumberId>0</StringNumberId><StringText /></LongDescriptor><MenuItemClassObjNum>0</MenuItemClassObjNum><NluGroupIndex>0</NluGroupIndex><SluIndex>0</SluIndex><HhtSluIndex>0</HhtSluIndex><MainLevels>00000000</MainLevels><SubLevels>00000000</SubLevels><PosRef>0</PosRef><PrintClassObjNum>0</PrintClassObjNum><PrefixLevelOverride>0</PrefixLevelOverride><GuestCount>0</GuestCount><MenuLevelEntries /><DefaultCondiments /><NextScreen /><MiMasterObjNum>10010000</MiMasterObjNum><CheckAvailability>false</CheckAvailability><OutOfMenuItem>false</OutOfMenuItem></DbMenuItemDefinition><DbMenuItemDefinition;</ArrayOfDbMenuItemDefinition></MenuItemDefinitions>**
</configInfoResponse>
</GetConfigurationInfoResponse>
</soap:Body>
</soap:Envelope>
How can I get value from this <MenuItemDefinitions></MenuItemDefinitions>? This xml element inside another XML data. How to say this kind of XML?
How to filter that value using PHP? I only need get value from the inside <MenuItemDefinitions></MenuItemDefinitions> xml value.
This is the soap request php code.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.5.10:8080/EGateway/SimphonyPosApiWeb.asmx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Body>
<GetConfigurationInfo>
<vendorCode />
<employeeObjectNum>10009</employeeObjectNum>
<configurationInfoType>
<int>1</int>
</configurationInfoType>
<revenueCenter>5</revenueCenter>
<configInfoResponse />
</GetConfigurationInfo>
</soap:Body>
</soap:Envelope>");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: text/xml;",
"SOAPAction: http://192.168.5.10:8080/EGateway/GetConfigurationInfo"
));
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);

Access web service via curl PHP or some thing similar

I have this type of API code and how can I send request to access this web service in php? can I use curl ? Please help me
Sandbox URL :
http://api.lankagate.gov.lk:8280/GetOnGoingVehicleNoDMT/1.0
Method POST
Parameter Name - vehicleCategory
Options - 1 , 4
Success Response Code: 200
<?xml version="1.0" encoding="utf-8"?>
<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>
<GetOnGoingVehicleNoResponse
xmlns="http://schemas.conversesolutions.com/xsd/dmticta/v1">
<return>
<ResponseMessage xsi:nil="true" />
<ErrorCode xsi:nil="true" />
<OngoingVehicleNo>CAW-2186</OngoingVehicleNo>
</return>
</GetOnGoingVehicleNoResponse>
</soap:Body>
</soap:Envelope>
Sample
Call URL : http://api.lankagate.gov.lk:8280/Transliteration/1.0/
Message body :
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://schemas.conversesolutions.com/xsd/dmticta/v1">
<soapenv:Header/>
<soapenv:Body>
<v1:GetOnGoingVehicleNo>
<v1:vehicleCategory>1</v1:vehicleCategory>
</v1:GetOnGoingVehicleNo>
</soapenv:Body>
</soapenv:Envelope>
Notes Set request header as
Authorization: Bearer Access Token
I have tried and this is my code
function get_exam_mode_of_study() {
$xml_data = '<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v1="http://schemas.conversesolutions.com/xsd/dmticta/v1">
<soapenv:Header/>
<soapenv:Body>
<v1:GetOnGoingVehicleNo>
<v1:vehicleCategory>1</v1:vehicleCategory>
</v1:GetOnGoingVehicleNo>
</soapenv:Body>
</soapenv:Envelope>';
$URL = "http://api.lankagate.gov.lk:8280/GetOnGoingVehicleNoDMT/1.0";
$ch = curl_init($URL);
// curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
print_r($output);
exit;
curl_close($ch);
// }
}
and it gives following error
<ams:fault xmlns:ams="http://wso2.org/apimanager/security"><ams:code>900902</ams:code><ams:message>Missing Credentials</ams:message><ams:description>Required OAuth credentials not provided. Make sure your API invocation call has a header: "Authorization: Bearer ACCESS_TOKEN"</ams:description></ams:fault>
You need to add the Authorization header
CURLOPT_HTTPHEADER for curl_setopt() takes an array with each header as an element.
You can use below $header array.
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer OAuthAccess_TokenThatIReceived';
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);

Echo PHP Variable in XML and Post value to webservice

I need to publish PHP variable values on SOAP-based web service some how I am not able to convert PHP POST values in XML elements.
How can I get POST variable, say abc, in sName element?
My code in PHP
<?php
//session_start();
$server_name= abc;
$xml_post_string = '<?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>
<createtest xmlns="http://tempuri.org/">
<sA>ADD</sA>
<sType>service</sType>
<sName>"$server_name"</sName>
</createtest>
</soap:Body>
</soap:Envelope>';
$headers = array(
"Content-Type: text/xml; charset=utf-8",
"Host: http://example.com",
"Content-length: ".strlen($xml_post_string),
"SOAPAction: http://tempuri.org/createtest"
);
url = 'http://example.com'; // WSDL web service url for request
method/function
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP
request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
echo $response = curl_exec($ch);
?>
You have to put quotes around abc, when you define the variable as a string:
$server_name = "abc";
And you could also put the variable in the string like this to make it easier to understand it as a variable in such a long string:
$xml_post_string = '<?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>
<createtest xmlns="http://tempuri.org/">
<sA>ADD</sA>
<sType>service</sType>
<sName>'.$server_name.'</sName>
</createtest>
</soap:Body>
</soap:Envelope>';

PHP - SOAP Request | XML/WSDL

I'm looking for a way to send a SOAP request from PHP code. An online game called MovieStarPlanet, has a "library" with many SOAP requests.
Here is the link to all queries:
http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx
The WSDL description:
http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL
The query is like this:
POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1
Host: http://www.moviestarplanet.fr
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://moviestarplanet.com/Login"
<?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>
<ThirdPartyTokenHeader xmlns="http://moviestarplanet.com/">
<ThirdPartyToken>string</ThirdPartyToken>
</ThirdPartyTokenHeader>
</soap:Header>
<soap:Body>
<Login xmlns="http://moviestarplanet.com/">
<username>string</username>
<password>string</password>
</Login>
</soap:Body>
</soap:Envelope>
And the answer to this query is:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?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>
<ThirdPartyTicketHeader xmlns="http://moviestarplanet.com/">
<Ticket>string</Ticket>
</ThirdPartyTicketHeader>
</soap:Header>
<soap:Body>
<LoginResponse xmlns="http://moviestarplanet.com/">
<LoginResult>
<ServiceResult>
<Codee>int</Codee>
<Description>string</Description>
</ServiceResult>
<ActorId>int</ActorId>
<AppToken>string</AppToken>
<UserInfo>
<FriendCount>int</FriendCount>
<MembershipTimeoutDate>dateTime</MembershipTimeoutDate>
<VipTier>int</VipTier>
<Level>int</Level>
<LockedUntil>dateTime</LockedUntil>
<LockedText>string</LockedText>
<SkinSWF>string</SkinSWF>
<LastLogin>dateTime</LastLogin>
</UserInfo>
</LoginResult>
</LoginResponse>
</soap:Body>
</soap:Envelope>
That would suggest a lot of account information when the username/password combination is correct.
I did a lot of research, but I don't know how to apply the code. Here's what I did:
$soap_request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$soap_request .= "<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/\">\n";
$soap_request .= " <soap:Header>\n";
$soap_request .= " <ThirdPartyTokenHeader xmlns=\"http://moviestarplanet.com/\">\n";
$soap_request .= " <ThirdPartyToken>8346D304-F85E-4dc1-98EB-033CBEE0217F</ThirdPartyToken>\n";
$soap_request .= " </ThirdPartyTokenHeader>\n";
$soap_request .= " </soap:Header>\n";
$soap_request .= " <soap:Body>\n";
$soap_request .= " <Login xmlns=\"http://moviestarplanet.com/\">\n";
$soap_request .= " <username>string</username>\n";
$soap_request .= " <password>string</password>\n";
$soap_request .= " </Login>\n";
$soap_request .= " </soap:Body>\n";
$soap_request .= "</soap:Envelope>";
$header = array(
"POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1",
"Host: http://www.moviestarplanet.fr",
"Content-type: text/xml; charset=utf-8",
"Content-length: ".strlen($soap_request),
"SOAPAction: \"http://moviestarplanet.com/Login\"",
);
$url = "http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL";
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, $url);
curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 10);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
if(curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
} else {
curl_close($soap_do);
print 'Success.';
}
When I run the code, it tells me an error: "Operation timed out after 10000 milliseconds with 0 bytes received".
Anyone can help me?
You are connecting to the wsdl file in your curl call. (
$url = "http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL")
The wsdl is NOT the webservice, the wsdl is a xml file with a description of the webservice.
Insted of doing all the low level coding using curl, you could use the SoapClient class:
$client=new SoapClient('http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL');
That way a lot of the basic communication with then webservice is handle automatic.
For example, you can start by listing all services on site:
print_r($client->__getFunctions());
I have found the soltuion! :)
<?php
$xml_data = '
<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>
<ThirdPartyTokenHeader xmlns="http://moviestarplanet.com/">
<ThirdPartyToken>8346D304-F85E-4dc1-98EB-033CBEE0217F</ThirdPartyToken>
</ThirdPartyTokenHeader>
</soap:Header>
<soap:Body>
<Login xmlns="http://moviestarplanet.com/">
<username>USER</username>
<password>PASS</password>
</Login>
</soap:Body>
</soap:Envelope>
';
$headers = array(
"POST /WebService/ThirdParty/ThirdPartyService.asmx HTTP/1.1",
"Referer: www.moviestarplanet.fr",
"User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; GT-I9505 Build/KOT49H)",
"Content-Type: text/xml; charset=utf-8",
"Host: www.moviestarplanet.fr",
"Content-length: ".strlen($xml_data),
"Expect: 100-continue"
);
$url = 'http://www.moviestarplanet.fr/WebService/ThirdParty/ThirdPartyService.asmx?WSDL';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
$reply = curl_exec($ch);
echo($reply);
?>

PHP soap xml request

I have tried to looking around the web and searching a lot but I can't figure out how to do this.
I want to make a SOAP request with a header and XML code.
This is how far I have come: created a variable that holds the header info:
$headers = array(
"POST /somefile.asmx HTTP/1.1",
"Host: a ip adress",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml_post_string)
);
and the xml I want to send looking like 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>
<GetViVaDataT xmlns="http://www.somesite.se/somefile.wsdl">
<PlatsId>int</PlatsId>
</GetViVaDataT>
</soap:Body>
</soap:Envelope>
But I have no idea how to go further. i'm using soap 1.2.
If other people have the same problem that I have, so here is what i did to get it to work.
$soapAction = 'http://www.somesite.com/path/to/file/file.wsdl/function';
$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:Body>
<GetViVaDataT xmlns="http://www.somesite.se/somefile.wsdl">
<PlatsId>int</PlatsId>
</GetViVaDataT>
</soap:Body>
</soap:Envelope>';
$headers = array(
"POST /site.asmx HTTP/1.1",
"Host: a ip adress",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($xml),
'SOAPAction:' .$soapAction
);
$curlData = $xml;
$url='http://site/file.asmx';
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_ENCODING,'xml');
curl_setopt($curl,CURLOPT_HTTPHEADER,$headers);
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);
$result = curl_exec($curl);

Categories