Jump to content

How to call web service?


Ty44ler

Recommended Posts

I have been given this web service, which I have been told will create an XML file once it is called through code, but I don't know how to get the XML from the web service in PHP.

 

The web service is only on our network and not public so I've posted the WSDL file below:

  <?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://tempuri.org/" 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://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
+ <s:element name="HelloWorld">
  <s:complexType /> 
  </s:element>
+ <s:element name="HelloWorldResponse">
- <s:complexType>
+ <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:element name="GetJobs">
  <s:complexType /> 
  </s:element>
- <s:element name="GetJobsResponse">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="GetJobsResult" type="tns:ArrayOfJobDAO" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:complexType name="ArrayOfJobDAO">
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="unbounded" name="JobDAO" nillable="true" type="tns:JobDAO" /> 
  </s:sequence>
  </s:complexType>
- <s:complexType name="JobDAO">
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="StatusCode" type="s:string" /> 
  <s:element minOccurs="1" maxOccurs="1" name="SRPWOHRID" type="s:int" /> 
  <s:element minOccurs="1" maxOccurs="1" name="CompanyNumber" type="s:int" /> 
  <s:element minOccurs="1" maxOccurs="1" name="DivisionNumber" type="s:int" /> 
  <s:element minOccurs="1" maxOccurs="1" name="CustomerNumber" type="s:int" /> 
  <s:element minOccurs="1" maxOccurs="1" name="RequestNo" type="s:int" /> 
  <s:element minOccurs="0" maxOccurs="1" name="RequestorName" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="AreaCode" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="PhoneNo" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Address1" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Address2" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="City" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="StateCode" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="ZipCode" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="RequestType" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="CustomerPONumber" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="Description" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:schema>
  </wsdl:types>
+ <wsdl:message name="HelloWorldSoapIn">
  <wsdl:part name="parameters" element="tns:HelloWorld" /> 
  </wsdl:message>
+ <wsdl:message name="HelloWorldSoapOut">
  <wsdl:part name="parameters" element="tns:HelloWorldResponse" /> 
  </wsdl:message>
- <wsdl:message name="GetJobsSoapIn">
  <wsdl:part name="parameters" element="tns:GetJobs" /> 
  </wsdl:message>
- <wsdl:message name="GetJobsSoapOut">
  <wsdl:part name="parameters" element="tns:GetJobsResponse" /> 
  </wsdl:message>
- <wsdl:portType name="Service1Soap">
- <wsdl:operation name="HelloWorld">
  <wsdl:input message="tns:HelloWorldSoapIn" /> 
  <wsdl:output message="tns:HelloWorldSoapOut" /> 
  </wsdl:operation>
- <wsdl:operation name="GetJobs">
  <wsdl:input message="tns:GetJobsSoapIn" /> 
  <wsdl:output message="tns:GetJobsSoapOut" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="Service1Soap" type="tns:Service1Soap">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="HelloWorld">
  <soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="GetJobs">
  <soap:operation soapAction="http://tempuri.org/GetJobs" 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="Service1Soap12" type="tns:Service1Soap">
  <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="HelloWorld">
  <soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="GetJobs">
  <soap12:operation soapAction="http://tempuri.org/GetJobs" 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="Service1">
- <wsdl:port name="Service1Soap" binding="tns:Service1Soap">
  <soap:address location="http://sqlsvr1/RefrigerantComplianceService/Service1.asmx" /> 
  </wsdl:port>
- <wsdl:port name="Service1Soap12" binding="tns:Service1Soap12">
  <soap12:address location="http://sqlsvr1/RefrigerantComplianceService/Service1.asmx" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

 

 

This is what I have so far, but the second line returns an error and I don't think it's at all right...

    $client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.wsdl");
   $result = $client->GetJobs(array());

 

My goal is to make a dynamic dropdown list that connects to another one of our servers using a web service.

 

How do I get this to return an XML file with the data that I can use to add to the drop down box?

Link to comment
Share on other sites

If anyone would like to help, it would be much appreciated...

 

From what I've been reading and looking at a few examples I've gotten this so far, but it still throws errors:

 

   $client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.wsdl");
$result = $client->GetJobs(array('GetJobs'));         //Error occurs on this line

    // Note that $array contains the result of the traversed object structure
     $array = $result->GetJobsResult->JobDAO;
    print "Service Description:<select><option>Please Select One</option>";
    foreach($array as $k=>$v){
        print "<option>".($k+1).$v->RequestNo."</option>".$v->Description."</td></tr>";
    }
    print "</select>";

 

Error:

Fatal error: Uncaught SoapFault exception: [HTTP] Not Found in C:\xampp\htdocs\compliance\tester2.php:22 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://sqlsvr1/...', 'http://tempuri....', 1, 0) #1 [internal function]: SoapClient->__call('GetJobs', Array) #2 C:\xampp\htdocs\compliance\tester2.php(22): SoapClient->GetJobs(Array) #3 {main} thrown in C:\xampp\htdocs\compliance\tester2.php on line 22

Link to comment
Share on other sites

Here's the error formatted better:

 

Fatal error:  Uncaught SoapFault exception: [HTTP] Not Found in C:\xampp\htdocs\compliance\tester2.php:46

Stack trace:

#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://sqlsvr1/...', 'http://tempuri....', 1, 0)

#1 [internal function]: SoapClient->__call('GetJobs', Array)

#2 C:\xampp\htdocs\compliance\tester2.php(46): SoapClient->GetJobs('description')

#3 {main}

  thrown in C:\xampp\htdocs\compliance\tester2.php on line 46

 

Still not sure what to do...

Link to comment
Share on other sites

You need to do some debugging it looks like.  My first guess is that the parameter for 'GetJobs'  is not an array.

 

Try adding in:

 

  $client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.wsdl", array("trace" => 1, "exceptions" => 0));
  $result = $client->GetJobs(array('GetJobs'));         //Error occurs on this line
  echo "\n";
  echo "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
  echo "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
  echo ""; 

    // Note that $array contains the result of the traversed object structure
     $array = $result->GetJobsResult->JobDAO;
    print "Service Description:Please Select One";
    foreach($array as $k=>$v){
        print "".($k+1).$v->RequestNo."".$v->Description."";
    }
    print "";

 

 

Link to comment
Share on other sites

You may be on to something... I was told when given the web service, that GetJobs() was a function that I needed to call which would give an xml file.

 

I may be on a tangent though as I'm pretty confused now...

 

Here's the output that I got (no errors!)

Request :

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:GetJobs/></SOAP-ENV:Body></SOAP-ENV:Envelope>

 

Response:

Service Description: Dropdown box was here with nothing inside

 

Link to comment
Share on other sites

Yeah things are pretty broken.  It also might be a good idea to see what functions are being made available from the wsdl:

 

$client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.wsdl", array("trace" => 1));
var_dump($client->__getFunctions());

Link to comment
Share on other sites

Yeah things are pretty broken.  It also might be a good idea to see what functions are being made available from the wsdl:

 

$client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.wsdl", array("trace" => 1));
var_dump($client->__getFunctions());

 

Yeah, I'm starting to get that feeling now too. I appreciate your help. I thought this would be a little easier...

 

Well anyway, here's the functions from the wsdl:

 

array(4) {

  [0]=>

  string(53) "HelloWorldResponse HelloWorld(HelloWorld $parameters)"

  [1]=>

  string(44) "GetJobsResponse GetJobs(GetJobs $parameters)"

  [2]=>

  string(53) "HelloWorldResponse HelloWorld(HelloWorld $parameters)"

  [3]=>

  string(44) "GetJobsResponse GetJobs(GetJobs $parameters)"

}

 

Also, I don't know if this helps anything, but GetJobs() has no parameters, which is kind of throwing me for a loop as well.

Link to comment
Share on other sites

Looking at the wsdl, these map to complextypes.  Thus you have to make an object to pass as the parameter, and it will likewise create an object on the return.  The problem is that i don't see a definition for the object, as it seems to be empty, so for example:

 


  

Link to comment
Share on other sites

Looking at the wsdl, these map to complextypes.  Thus you have to make an object to pass as the parameter, and it will likewise create an object on the return.  The problem is that i don't see a definition for the object, as it seems to be empty, so for example:

 

<s:element name="GetJobs">
  <s:complexType /> 

 

Ok, I'm going to try and take a step back here. If I were to simply say I wanted to list all the RequestNo's would that be possible?

 

Just forgetting all the stuff except for this line:

$client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.wsdl", array("trace" => 1, "exceptions" => 0));

Would it be possible to just list all the data in RequestNo's?

Link to comment
Share on other sites

Well, I've updated my code a little bit, figured out that I should be using non-wsdl mode...

 

Here's my code now:

$aOptions = array(
    'location' => 'http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx',
    'uri' => 'http://tempuri.org/'
);
$client = new SOAPClient(null, $aOptions);  

$result = $client->__soapCall('GetJobs', array()); //line 51

 

and the error I receive...

Fatal error:  Uncaught SoapFault exception: [soap:Client] Server did not recognize the value of HTTP Header SOAPAction: http://tempuri.org/#GetJobs. in C:\xampp\htdocs\compliance\tester2.php:51

Stack trace:

#0 C:\xampp\htdocs\compliance\tester2.php(51): SoapClient->__soapCall('GetJobs', Array)

#1 {main}

  thrown in C:\xampp\htdocs\compliance\tester2.php on line 51

 

Getting there... any help would still be appreciated...

Link to comment
Share on other sites

Well, with a little help I've got it to connect.

 

$aOptions = array(
    'location' => 'http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx',
    'uri' => 'http://tempuri.org/'
);
$client = new SOAPClient(null, $aOptions);  

$result = $client->__soapCall('GetJobs', array(), array('soapaction' => 'http://tempuri.org/GetJobs'));  

 

Now that it connects, how do I go about displaying a list of data? like the 'RequestNo' data?

Link to comment
Share on other sites

Got it:

Basically I was using:

http://refrigerantcompliance/RefrigerantComplianceService/Service1.WSDL

 

When I should have been using:

http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx?wsdl

 

Final code:

$client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx?wsdl");
$result = $client->__soapCall('GetJobs', array());  

$array = $result->GetJobsResult->JobDAO;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.