How to create SOAP 1.2 request - php

I need help with creating SOAP 1.2 request. All i have is this:
SAMPLE REQUEST:
POST /WS/PriceList.asmx HTTP/1.1
Host: gateway.systemb2b.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12: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">
<soap12:Body>
<GetProducts xmlns="http://gateway.systemb2b.com/schemas/Product" />
</soap12:Body>
</soap12:Envelope>
SAMPLE RESPONSE:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12: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">
<soap12:Body>
<GetProductsResponse xmlns="http://gateway.systemb2b.com/schemas/Product">
<GetProductsResult>xml</GetProductsResult>
</GetProductsResponse>
</soap12:Body>
</soap12:Envelope>
Thanks a lot.

<?php
$client = new SoapClient("URL/OF/YOUR/WSDL", array('soap_version' => SOAP_1_2));
$result = $client('GetProducts');
?>

I hope this example would help you to get your issue solved. All the best!
// SOAP 1.2 client
$options = array('soap_version'=>SOAP_1_2, 'exceptions'=>true, 'trace'=>1);
$client = new SoapClient('https://www.example.com/example.svc/SSL?wsdl', $options);
$actionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing','Action','http://tempuri.org/xxxx/GetResult');
$toActionHeader = new SoapHeader('http://www.w3.org/2005/08/addressing','To','https://www.example.com/example.svc/SSL?wsdl');
$headerbody = array('Action' => $actionHeader,'To' => $toActionHeader);
$client->__setSoapHeaders($headerbody);
$client->__setLocation('https://www.example.com/example.svc/SSL');
$params = array( "param1"=>"abc", "param2"=>"ab123",c"param3"=>"ab1111" );
$client->__soapCall("GetResult", array($params));

Related

PHP function SOAP 1.2

I need some help to execute a SOAP request with PHP.
For example, a method for search a publisher:
POST /webservice/search.asmx HTTP/1.1
Host: www.host.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://host.com/HostNET/" xmlns:types="http://host.com/HostNET/encodedTypes" xmlns:rpc="http://www.w3.org/2003/05/soap-rpc" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body soap12:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<tns:findPublishers>
<sessionToken xsi:type="xsd:string">string</sessionToken>
<expression soapenc:id="id0" xsi:type="tns:SearchExpression">
<expression xsi:type="xsd:string">string</expression>
<phonetic xsi:type="xsd:boolean">boolean</phonetic>
<inflections xsi:type="xsd:boolean">boolean</inflections>
</expression>
<distributeurs xsi:type="xsd:boolean">boolean</distributeurs>
</tns:findPublishers>
</soap12:Body>
</soap12:Envelope>
I have the sessionToken but I don't understand what I have to do with the line <expression soapenc:id="id0" xsi:type="tns:SearchExpression"> and it's contents.
try{
$search = new SoapClient("http://www.host.com/WebService/search.asmx?wsdl", array("soap_version" => SOAP_1_2));
$search->findPublishers($sessionToken,???????,FALSE);
}catch (SoapFault $e){
print_r($e);
}

php soap client connection

Hi I have the fallowing soap
SOAP 1.1
POST /ServicePeletalk.asmx HTTP/1.1
Host: 82.80.225.186
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://peletop.co.il/GetProducts"
<?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>
<GetProducts xmlns="http://peletop.co.il/">
<query>
<TerminalNum>string</TerminalNum>
<ProviderID>int</ProviderID>
<CardType>All or Virtual or Manual or BillPayment</CardType>
<Language>Hebrew or Arabic or English</Language>
<LoadPictures>boolean</LoadPictures>
</query>
</GetProducts>
</soap:Body>
</soap:Envelope>
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:Body>
<GetProductsResponse xmlns="http://peletop.co.il/">
<GetProductsResult>
<Products>
<clsProduct>
<ProductIdenfity>string</ProductIdenfity>
<ProductName>string</ProductName>
<Description>string</Description>
<Picture>base64Binary</Picture>
<Price>double</Price>
<MaxPrice>double</MaxPrice>
<CardType>All or Virtual or Manual or BillPayment</CardType>
<DetailsLink>string</DetailsLink>
</clsProduct>
<clsProduct>
<ProductIdenfity>string</ProductIdenfity>
<ProductName>string</ProductName>
<Description>string</Description>
<Picture>base64Binary</Picture>
<Price>double</Price>
<MaxPrice>double</MaxPrice>
<CardType>All or Virtual or Manual or BillPayment</CardType>
<DetailsLink>string</DetailsLink>
</clsProduct>
</Products>
</GetProductsResult>
</GetProductsResponse>
</soap:Body>
</soap:Envelope>
SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.
POST /ServicePeletalk.asmx HTTP/1.1
Host: 82.80.225.186
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12: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">
<soap12:Body>
<GetProducts xmlns="http://peletop.co.il/">
<query>
<TerminalNum>string</TerminalNum>
<ProviderID>int</ProviderID>
<CardType>All or Virtual or Manual or BillPayment</CardType>
<Language>Hebrew or Arabic or English</Language>
<LoadPictures>boolean</LoadPictures>
</query>
</GetProducts>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12: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">
<soap12:Body>
<GetProductsResponse xmlns="http://peletop.co.il/">
<GetProductsResult>
<Products>
<clsProduct>
<ProductIdenfity>string</ProductIdenfity>
<ProductName>string</ProductName>
<Description>string</Description>
<Picture>base64Binary</Picture>
<Price>double</Price>
<MaxPrice>double</MaxPrice>
<CardType>All or Virtual or Manual or BillPayment</CardType>
<DetailsLink>string</DetailsLink>
</clsProduct>
<clsProduct>
<ProductIdenfity>string</ProductIdenfity>
<ProductName>string</ProductName>
<Description>string</Description>
<Picture>base64Binary</Picture>
<Price>double</Price>
<MaxPrice>double</MaxPrice>
<CardType>All or Virtual or Manual or BillPayment</CardType>
<DetailsLink>string</DetailsLink>
</clsProduct>
</Products>
</GetProductsResult>
</GetProductsResponse>
</soap12:Body>
</soap12:Envelope>
how do I write it in PHP???
I tried
<?
// Maximum error reporting
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
$wsdl = 'http://82.80.225.186:8000/ServicePeletalk.asmx?WSDL';
$trace = true;
$exceptions = true;
$client = new SoapClient($wsdl, array( 'trace' => $trace, 'exceptions' => $exceptions));
$xml_array['TerminalNum'] = 5089 ;
$xml_array['UserType'] = 'SiteUser';
$xml_array['Language'] = 'English';
$xml_array['ConnectionOrDeviceID'] = '879d62-EA47-4520-8A29-EB5981A62DD8';
try
{
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->GetSellerProviders($xml_array);
}
catch (Exception $e)
{
echo "Error!";
echo $e -> getMessage ();
echo 'Last response: '. $client->__getLastResponse();
}
?>
it's not working
please help
For a first look, it seems that, based on your xml files, you have to call $client->GetProducts instead of $client->GetSellerProviders, because there is an element named GetProducts in your xml files.
If this was a typo and you really call $client->GetProducts then check for $xml_array structure to be like this
$xml_array['query']['TerminalNum'] = 5089 ;
$xml_array['query']['UserType'] = 'SiteUser';
$xml_array['query']['Language'] = 'English';
$xml_array['query']['ConnectionOrDeviceID'] = '879d62-EA47-4520-8A29-EB5981A62DD8';
include query element as shown in xml request sample.
UPDATE from comments
I see that the request xml has the following elements
<TerminalNum>string</TerminalNum>
<ProviderID>int</ProviderID>
<CardType>All or Virtual or Manual or BillPayment</CardType>
<Language>Hebrew or Arabic or English</Language>
<LoadPictures>boolean</LoadPictures>
So the $xml_array variable should have an array with the names of these elements like:
$xml_array['query']['TerminalNum'] = 5089 ;
$xml_array['query']['ProviderID'] = 'SiteUser';
$xml_array['query']['CardType'] = 'som card type';
$xml_array['query']['Language'] = 'English';
$xml_array['query']['LoadPictures'] = 'true';

Connect to sample SOAP 1.1 with PHP

Hello i need to connect to SOAP web services with password, username and SourceId in php.
the SOAP request is:
POST /webservices/AgentOnlineReservation.asmx HTTP/1.1
Host: 54.228.189.53
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetHotelsData"
<?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>
<GetHotelsData xmlns="http://tempuri.org/">
<SourceId>string</SourceId>
<UserName>string</UserName>
<Password>string</Password>
</GetHotelsData>
</soap:Body>
</soap:Envelope>
Please help me.
Use the native SoapClient library:
$client = new SoapClient('linkhere.com/AgentOnlineReservation.asmx?wsdl');
$response = $client->GetHotelsData(array(
'SourceId' => '...',
'UserName' => '...',
'Password' => '...'
));
print_r($response);
The link passed in the SoapClient call is the WSDL (Web Service Description Language) file.

Consume a .Net web service using PHP

This is my first time with web services/SOAP...i have been trying to consume .Net web services using PHP but to no avail. I have searched and read all pages that google throws up for anything related to this but i am still lost.
The thing is the SOAP service i am trying to call has an authorization header and i can't figure out a way to authenticate my request.
I have tried the php-soapclient and NuSoap both but there is no sample code available that would help. So any help would be great.
The following is a sample SOAP 1.1 request and response.
POST /OxiWalletService/Service.asmx HTTP/1.1
Host: 172.160.0.49
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/WS_GetData"
<?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://tempuri.org/">
<UserName>string</UserName>
<Password>string</Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<WS_GetData xmlns="http://tempuri.org/">
<xmlString>string</xmlString>
</WS_GetData>
</soap:Body>
</soap:Envelope>
Response
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:Body>
<WS_GetDataResponse xmlns="http://tempuri.org/">
<WS_GetDataResult>string</WS_GetDataResult>
</WS_GetDataResponse>
</soap:Body>
</soap:Envelope>
Can anybody please gimme a sample code on how to consume such a service.
Many thanks in advance!
This is the code that i have used to call the web service
<?php
$soap_client = new SoapClient("http://172.160.0.49/OxiWalletService/Service.asmx?WSDL");
$Uid='oxigen';
$Pwd='oxigen';
$ns = "http://tempuri.org/";
//Body of the Soap Header.
$headerbody = array('UserName' => $Uid,
'Password' => $Pwd
);
//Create Soap Header.
$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);
//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);
$par="<Wallet><SPName>AuthenticateMerchantWebVending</SPName><Parameters><Parameter><Name>#Account</Name><Size>50</Size><Value>1135600016</Value><Type>varchar</Type></Parameter><Parameter><Name>#Password</Name><Size>20</Size><Value>0OgknrdonyM=</Value><Type>varchar</Type></Parameter></Parameters><ParameterCount>2</ParameterCount><DataBase>1</DataBase></Wallet>";
$param=array('xmlString'=>$par);
$result=$soap_client->__SoapCall('WS_GetData',$param);
print_r ($result);
?>
and i am getting the following as output:
stdClass Object ( [WS_GetDataResult] => 2Unknown Error )
Ideas??
So it turns out you've to pass the second argument with parameters as the key of the array
meaning this
$result=$soap_client->__SoapCall('WS_GetData',$param);
should be
$result=$soap_client->__SoapCall('WS_GetData',array('parameters'=>$param));
This works now.
I think this should do the trick:
www.php.net/manual/en/soapclient.setsoapheaders.php
$ns = "http://tempuri.org/"
//Body of the Soap Header.
$headerbody = array('UserName' => $yourUsername,
'Password' => $yourPassword,
);
//Create Soap Header.
$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);
//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);

PHP SOAP client help!

I have to create a PHP SOAP client that sends leads, but I have never worked with SOAP before, and my XML isn't that great, here is the code I have managed to write so far. . .
<?php
try {
$client = new SoapClient(null, array(
'location' => "https://wwa.website.co.za/CallmasterTes/LeadService.asmx",
'uri' => "urn:Website:Callmaster:InTuch/CreateLead",
'login' => "username",
'password' => "password"
));
$sysName = ' ';
$clientCode = ' ';
$expTimestamp = ' ';
$schedTimestamp = ' ';
$client->CreateLead("ExternalLead",
new SoapParam($sysName, "BusinessSystemName"),
new SoapParam($clientCode, "BusinessSystemClientCode"),
new SoapParam($_POST['Title'], "Title"),
new SoapParam($_POST['FirstName'], "FirstName"),
new SoapParam($_POST['Surname'], "Surname"),
new SoapParam($_POST['IdNumber'], "IdNumber"),
new SoapParam($_POST['Gender'], "Gender"),
new SoapParam($_POST['DateOfBirth'], "DateOfBirth"),
new SoapParam($_POST['Language'], "Language"),
new SoapParam($_POST['EmailAddress'], "EmailAddress"),
new SoapParam($_POST['HomeTelNumber'], "HomeTelNumber"),
new SoapParam($_POST['BusinessTelNumber'], "BusinessTelNumber"),
new SoapParam($_POST['MobileTelNumber'], "MobileTelNumber"),
new SoapParam($_POST['OtherTelNumber'], "OtherTelNumber"),
new SoapParam($_POST['PreferredTelNumberCode'], "PreferredTelNumberCode"),
new SoapParam($_POST['CampaignName'], "CampaignName"),
new SoapParam($_POST['ProductName'], "ProductName"),
new SoapParam($_POST['Comments'], "Comments"),
new SoapParam($expTimestamp, "ExpiryTimestamp"),
new SoapParam($schedTimestamp, "ScheduledTimestamp"),
);
}
catch (SoapFault $fault) {
trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
}
?>
The following is a sample SOAP 1.2 request and response that I was given by the developers on the server side of things.
POST /CallmasterTest/LeadService.asmx HTTP/1.1
Host: wwa.website.co.za
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12: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">
<soap12:Body>
<CreateLead xmlns="urn:Website:Callmaster:InTuch">
<Lead>
<BusinessSystemName>string</BusinessSystemName>
<BusinessSystemClientCode>int</BusinessSystemClientCode>
<Title>Mr or Ms or Mrs or Miss...etc</Title>
<FirstName>string</FirstName>
<Surname>string</Surname>
<IdNumber>string</IdNumber>
<Gender>Male or Female</Gender>
<DateOfBirth>date</DateOfBirth>
<Language>string</Language>
<EmailAddress>string</EmailAddress>
<HomeTelNumber>string</HomeTelNumber>
<BusinessTelNumber>string</BusinessTelNumber>
<MobileTelNumber>string</MobileTelNumber>
<OtherTelNumber>string</OtherTelNumber>
<PreferredTelNumberCode>Business or Home or Mobile or Other</PreferredTelNumberCode>
<CampaignName>string</CampaignName>
<ProductName>string</ProductName>
<Comments>string</Comments>
<ExpiryTimestamp>dateTime</ExpiryTimestamp>
<ScheduledTimestamp>dateTime</ScheduledTimestamp>
</Lead>
</CreateLead>
</soap12:Body>
</soap12:Envelope>
The response:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12: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">
<soap12:Body>
<CreateLeadResponse xmlns="urn:Website:Callmaster:InTuch">
<CreateLeadResult>
<Success>boolean</Success>
<StatusMessage>string</StatusMessage>
<LeadGuid>guid</LeadGuid>
<Errors>
<LeadError ErrorLevel="Information or Warning or Error">
<Message>string</Message>
<Field>string</Field>
</LeadError>
<LeadError ErrorLevel="Information or Warning or Error">
<Message>string</Message>
<Field>string</Field>
</LeadError>
</Errors>
</CreateLeadResult>
</CreateLeadResponse>
</soap12:Body>
</soap12:Envelope>
I have really tried everything, and googled into high heaven, but I just can't get it to work, I am sure that it's probably something small that I am missing, I would really appreciate the help, thanx!
I'm not sure if this is a copy/paste error or not, but all the _POSTs should be $_POSTs in your first code example.

Categories