Page 1 of 1

Php Soap client

Posted: Tue Aug 21, 2007 6:35 am
by phpcoder
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,
I got soap server
wsdl file 
[syntax="xml"]

<?xml version="1.0" encoding="utf-8" ?> 
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://uk.co.macs-software/WMSOrderFulfilment/" xmlns:s1="http://uk.co.macs-software.integration.wms.messagetypes/v1.00" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://uk.co.macs-software/WMSOrderFulfilment/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://uk.co.macs-software/WMSOrderFulfilment/">
  <s:import namespace="http://uk.co.macs-software.integration.wms.messagetypes/v1.00" /> 
- <s:element name="PlaceOrder">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" ref="s1:OrderForm" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:element name="PlaceOrderResponse">
  <s:complexType /> 
  </s:element>
- <s:element name="CancelOrder">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" ref="s1:OrderCancellation" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:element name="CancelOrderResponse">
  <s:complexType /> 
  </s:element>
  </s:schema>
- <s:schema elementFormDefault="qualified" targetNamespace="http://uk.co.macs-software.integration.wms.messagetypes/v1.00">
  <s:element name="OrderForm" type="s1:OrderForm" /> 
- <s:complexType name="OrderForm">
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="OrderNumber" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="AccountNo" type="s:string" /> 
  <s:element minOccurs="1" maxOccurs="1" name="Store" type="s1:OrderFormStore" /> 
  <s:element minOccurs="0" maxOccurs="1" name="DeliveryName" type="s:string" /> 
  <s:element minOccurs="1" maxOccurs="1" name="DeliveryOption" type="s1:OrderFormDeliveryOption" /> 
  <s:element minOccurs="0" maxOccurs="1" name="DeliveryCharge" type="s:decimal" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Address" type="s1:Address" /> 
  <s:element minOccurs="0" maxOccurs="unbounded" name="Item" type="s1:Item" /> 
  <s:element minOccurs="0" maxOccurs="1" name="CreditCardDetails" type="s1:CreditCardDetails" /> 
  <s:element minOccurs="0" maxOccurs="1" name="OrderLevelDiscount" type="s:decimal" /> 
  </s:sequence>
  </s:complexType>
- <s:simpleType name="OrderFormStore">
- <s:restriction base="s:string">
  <s:enumeration value="NoneSpecified" /> 
  <s:enumeration value="Star" /> 
  </s:restriction>
  </s:simpleType>
- <s:simpleType name="OrderFormDeliveryOption">
- <s:restriction base="s:string">
  <s:enumeration value="NextDay" /> 
  <s:enumeration value="Standard" /> 
  </s:restriction>
  </s:simpleType>
- <s:complexType name="Address">
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="AddressLine1" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="AddressLine2" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Town" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="County" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Postcode" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Country" type="s:string" /> 
  </s:sequence>
  </s:complexType>
- <s:complexType name="Item">
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="Sku" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Description" type="s:string" /> 
  <s:element minOccurs="1" maxOccurs="1" name="Quantity" type="s:int" /> 
  <s:element minOccurs="1" maxOccurs="1" name="Price" type="s:decimal" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Discount" type="s:decimal" /> 
  <s:element minOccurs="1" maxOccurs="1" name="VatAmount" type="s:decimal" /> 
  <s:element minOccurs="1" maxOccurs="1" name="TotalAmountIncludingVat" type="s:decimal" /> 
  </s:sequence>
  </s:complexType>
- <s:complexType name="CreditCardDetails">
- <s:sequence>
  <s:element minOccurs="1" maxOccurs="1" name="LastFourDigits" type="s:int" /> 
  <s:element minOccurs="1" maxOccurs="1" name="CreditCardType" type="s1:CreditCardDetailsCreditCardType" /> 
  </s:sequence>
  </s:complexType>
- <s:simpleType name="CreditCardDetailsCreditCardType">
- <s:restriction base="s:string">
  <s:enumeration value="Visa" /> 
  <s:enumeration value="Master Card" /> 
  <s:enumeration value="Delta" /> 
  <s:enumeration value="Switch / UK Maestro" /> 
  <s:enumeration value="Visa Electron" /> 
  <s:enumeration value="Solo" /> 
  <s:enumeration value="Maestro" /> 
  <s:enumeration value="American Express" /> 
  </s:restriction>
  </s:simpleType>
  <s:element name="OrderCancellation" type="s1:OrderCancellation" /> 
- <s:complexType name="OrderCancellation">
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="OrderNumber" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:schema>
  </wsdl:types>
- <wsdl:message name="PlaceOrderSoapIn">
  <wsdl:part name="parameters" element="tns:PlaceOrder" /> 
  </wsdl:message>
- <wsdl:message name="PlaceOrderSoapOut">
  <wsdl:part name="parameters" element="tns:PlaceOrderResponse" /> 
  </wsdl:message>
- <wsdl:message name="CancelOrderSoapIn">
  <wsdl:part name="parameters" element="tns:CancelOrder" /> 
  </wsdl:message>
- <wsdl:message name="CancelOrderSoapOut">
  <wsdl:part name="parameters" element="tns:CancelOrderResponse" /> 
  </wsdl:message>
- <wsdl:portType name="OrderingSoap">
- <wsdl:operation name="PlaceOrder">
  <wsdl:input message="tns:PlaceOrderSoapIn" /> 
  <wsdl:output message="tns:PlaceOrderSoapOut" /> 
  </wsdl:operation>
- <wsdl:operation name="CancelOrder">
  <wsdl:input message="tns:CancelOrderSoapIn" /> 
  <wsdl:output message="tns:CancelOrderSoapOut" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="OrderingSoap" type="tns:OrderingSoap">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="PlaceOrder">
  <soap:operation soapAction="http://uk.co.macs-software/WMSOrderFulfilment/PlaceOrder" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="CancelOrder">
  <soap:operation soapAction="http://uk.co.macs-software/WMSOrderFulfilment/CancelOrder" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:binding name="OrderingSoap12" type="tns:OrderingSoap">
  <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="PlaceOrder">
  <soap12:operation soapAction="http://uk.co.macs-software/WMSOrderFulfilment/PlaceOrder" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="CancelOrder">
  <soap12:operation soapAction="http://uk.co.macs-software/WMSOrderFulfilment/CancelOrder" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="Ordering">
- <wsdl:port name="OrderingSoap" binding="tns:OrderingSoap">
  <soap:address location="http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx" /> 
  </wsdl:port>
- <wsdl:port name="OrderingSoap12" binding="tns:OrderingSoap12">
  <soap12:address location="http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>
Now I want to write a PHP client is I need bit of start if some one can help me with this
Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Aug 21, 2007 6:39 am
by volka
please try

Code: Select all

<?php
if ( !extension_loaded('soap') ) {
	echo 'php version: ', phpversion(), "<br />\n";
	echo 'soap extension not present';
	die();
}

$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
print_r($client->__getFunctions());

Posted: Tue Aug 28, 2007 8:41 am
by phpcoder
volka wrote:please try

Code: Select all

<?php
if ( !extension_loaded('soap') ) {
	echo 'php version: ', phpversion(), "<br />\n";
	echo 'soap extension not present';
	die();
}

$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
print_r($client->__getFunctions());
The response from server is


Array ( [0] => PlaceOrderResponse PlaceOrder(PlaceOrder $parameters) [1] => CancelOrderResponse CancelOrder(CancelOrder $parameters) [2] => PlaceOrderResponse PlaceOrder(PlaceOrder $parameters) [3] => CancelOrderResponse CancelOrder(CancelOrder $parameters) )

Posted: Tue Aug 28, 2007 6:39 pm
by volka
Now you can call the defined operations, like e.g.

Code: Select all

<?php
$client = new SoapClient('http://www.webservicex.net/geoipservice.asmx?WSDL');
$response = $client->GetGeoIP(array('IPAddress'=>'88.72.14.195'));
$georesult = $response->GetGeoIPResult;

echo "<pre>\n";
echo $georesult->IP, "\n";
echo $georesult->CountryName, "\n";
echo "</pre>\n";
?>
http://www.webservicex.net/geoipservice.asmx?WSDL defines an operation GetGeoIP that takes a string parameter called IPAddress

Posted: Wed Aug 29, 2007 3:10 am
by phpcoder
volka wrote:Now you can call the defined operations, like e.g.

Code: Select all

<?php
$client = new SoapClient('http://www.webservicex.net/geoipservice.asmx?WSDL');
$response = $client->GetGeoIP(array('IPAddress'=>'88.72.14.195'));
$georesult = $response->GetGeoIPResult;

echo "<pre>\n";
echo $georesult->IP, "\n";
echo $georesult->CountryName, "\n";
echo "</pre>\n";
?>
http://www.webservicex.net/geoipservice.asmx?WSDL defines an operation GetGeoIP that takes a string parameter called IPAddress
Hi,
Could you please tell me what this array means
Array ( [0] => PlaceOrderResponse PlaceOrder(PlaceOrder $parameters)

I know it says there is a function named placeorder and PlaceOrderResponse but what this array is for? I tried this php client

Code: Select all

<?php 
if ( !extension_loaded('soap') ) { 
        echo 'php version: ', phpversion(), "<br />\n"; 
        echo 'soap extension not present'; 
        die(); 
} 

$client = new SoapClient('http://www.macs-software.co.uk/starws/WMSOrderfulfilment.asmx?WSDL');
print_r($client->__getFunctions());
$ response = $client->PlaceOrder(1,2,3,4);

?>
I got the following error

Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\wamp\www\testsoap.php:10 Stack trace: #0 [internal function]: SoapClient->__call('PlaceOrder', Array) #1 C:\wamp\www\testsoap.php(10): SoapClient->PlaceOrder(1, 2, 3, 4) #2 {main} thrown in C:\wamp\www\testsoap.php on line 10

Please help me to write this soap client.
Thanks