views:

152

answers:

1

I am new to php and webservices so pls bare with me

The following is my webservice calling 2 methods from dataclass (registerCustomer and getCountries)

<!-- a string array req param, used as a return for the getAvailable cars method -->
<message name="response">
<part name="resParam" type="tns:strArray"/>
</message>

<!-- just a string message -->
<message name="request">
  <part name="reqParam" type="xsd:string"/>
</message>

<!-- Methods published, together with there inputs and outputs -->
<portType name="testPortType">
<!-- Method 0. Takes nothing returns a string array -->
    <operation name="getCountries">
 <output message="tns:response"/>
</operation>
<!-- Method 1. Takes a string param and returns nothing -->
<operation name="registerCustomer">
 <input message="tns:request"/>
</operation>
<!-- Method 2. Takes a string param and returns nothing  -->
<operation name="">
 <input message="tns:request"/>
</operation>
</portType>

<!-- define the transport and protocol -->
<binding name="testBinding" type="tns:testPortType">
 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/&gt;
  <operation name="getCountries">
     <soap:operation soapAction=""/>
<output>
<soap:body use="encoded"  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:mymyInputNamespace"/>
    </output>

</operation>
<operation name="registerCustomer">
    <soap:operation soapAction=""/>
    <input>
 <soap:body use="encoded"  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:mymyInputNamespace"/>
</input>
</operation>
</binding>

<!-- who implements these services ? -->
   <service name="testService">
    <port name="testPort" binding="tns:testBinding">
     <soap:address location="http://localhost/dataobjects/dataclass.php"/&gt;

From the php page they are not accessible and it is giving me the following error:

Fatal error: Call to undefined method SoapServer::getCountries() in C:\Program Files\xampplite\htdocs\testingpage.php on $dataset = $dataobj->getCountries();

$dataobj = new SoapServer("http://localhost/dataobjects/myWebservice.wsdl", array('soap_version' => SOAP_1_2,'trace' => 1 ));
$dataset = $dataobj->getCountries();
 echo("<h2>Available Countries (".count($dataset)."):</h2><br />");

 foreach($dataset as $c) {
 echo($c.", ");
A: 

To call a web service, try something like this:

try{
 $service = "http://example.org/myWebService.wsdl";
 $client = new SoapClient($service, array('location' =>"http://example.org/myWebService"));
 $parameter1 = new myWebServiceParameter();
 $result = $client->myWebServiceFunction($parameter1);
} catch (Exception $e) {
 // handle errors
}

You must provide the URL of the web service endpoint not to your wsdl. myWebServiceParameter must be any class with a member variable foreach WSDL message attribute of the same name. And myWebServiceFunction is the name of the web service method.

For your web service it could be:

try{
 $service = "http://localhost/dataobjects/myWebservice.wsdl";
 $client = new SoapClient($service, array('location' =>"http://localhost/dataobjects/myWebservice"));
 $result = $client->getCountries();
} catch (Exception $e) {
 // handle errors
}
Christian Strempfer
tried it out as you told me:try{ $service = "http://localhost/dataobjects/myWebservice.wsdl"; $dataobj = new SoapClient($service, array('location' =>"http://localhost/dataobjects/myWebservice")); $dataset = $dataobj->getCountries(); } catch (Exception $e) {echo $e; }now it is giving me another error:SoapFault exception: [Client] DTD are not supported by SOAP in C:\Program Files\xampplite\htdocs\testingpage.php:13 Stack trace: #0 [internal function]: SoapClient->__call('getCountries', Array) #1 C:\Program Files\xampplite\htdocs\testingpage.php(13): SoapClient->getCountries() #2 {main}
IanCian
You must not use a DTD to validate your XML message, instead use a XML Schema (or nothing).
Christian Strempfer