...

View Full Version : SOAP not connecting



Ty44ler
01-06-2010, 06:01 PM
I have a web service that a co worker of mine wrote. I'm trying to connect to it and use the data from it to display selections in a selection box.

It doesn't connect to the service though. The WSDL file has been created and can be displayed in the browser: http://sqlsvr1/RefrigerantComplianceService/Service1.WSDL

Here's my code:

$client = new SoapClient("http://sqlsvr1/RefrigerantComplianceService/Service1.WSDL");
$result = $client->GetJobs();

It brings up all kinds of errors:

Warning: SoapClient::SoapClient() [soapclient.soapclient]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\My Dropbox\compliance\tester2.php on line 4

Warning: SoapClient::SoapClient(http://sqlsvr1/RefrigerantComplianceService/Service1.WSDL) [soapclient.soapclient]: failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\My Dropbox\compliance\tester2.php on line 4

Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning : failed to load external entity "http://sqlsvr1/RefrigerantComplianceService/Service1.WSDL" in C:\EDITED\EDITED\tester2.php on line 4

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://sqlsvr1/RefrigerantComplianceService/Service1.WSDL' : failed to load external entity "http://sqlsvr1/RefrigerantComplianceService/Service1.WSDL" in C:\EDITED\tester2.php:4 Stack trace: #0 C:\EDITED\EDITED\tester2.php(4): SoapClient->SoapClient('http://sqlsvr1/...') #1 {main} thrown in C:\EDITED\tester2.php on line 4

What is going on here? I tried connecting to other public web services like amazon and it works without error.

Also have PHP5 and SOAP installed.

Fou-Lu
01-06-2010, 08:08 PM
This is an invalid domain: http://sqlsvr1/RefrigerantComplianceService
If the domain cannot be resolved, use the IP address for it instead.

Ty44ler
01-20-2010, 04:26 PM
This is an invalid domain: http://sqlsvr1/RefrigerantComplianceService
If the domain cannot be resolved, use the IP address for it instead.

Thanks for the response and sorry for the delay...

The web service is only on our network and not public which is why it wasn't working 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>

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.

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?

Ty44ler
01-20-2010, 07:44 PM
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: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

Fou-Lu
01-20-2010, 10:55 PM
That looks like the wsdl file choking now. Same problem would be my guess, the http://sqlsvr1 cannot be resolved to a host. You can replace this with a domain or ip address though.
Technically, you do not need a wsdl in order to write web services. You just need to know what to expect.
Check out the __construct method of the SOAPClient class in the api, one of the examples should show you how to construct the service without a wsdl.
Best I can tell (and its been awhile since I've read wsdl files), the getJobs is a no parameter method, so you shouldn't need to provide it with any arguments. You'll need to get through the whole resolution problem first though.


Mkay, so a little alteration from the above. The error message on an invalid domain is 'Could not connect to host'. When I have the correct host with an incorrect path to a soap server, the message is 'Not Found', same as you have. These are not triggered on construct as I expected, rather they are triggered on call.
So, it looks like all you need to do is ensure that the path to the file is correct from you're http root. The host is fine in this case with http://refrigerantcompliance, but the path from there appears to be invalid.

Ty44ler
01-21-2010, 02:21 PM
Yes, I thought that was the case as well, but I tried it on a server within our network and the WSDL showed up. I believe it can only be accessed within our firewall (which is fine since the service will only be run on our intranet).

If I were wanting to just display all the data in "description" from JobDAO would that be possible?

Fou-Lu
01-21-2010, 02:33 PM
Yeah, but its been a long time myself since I did soap work, so you'll need to play around with you're results to see what datatypes and storage are in use. I'm thinking it should be a returned associative array.

Ty44ler
01-21-2010, 02:44 PM
I appreciate your help. I might be in over my head on this one. This is my first time ever attempting SOAP.

The problem is I'm not really getting any results, just errors and when I do, I'm not exactly sure what they mean.

Fou-Lu
01-21-2010, 03:29 PM
var_dump anything you need, it will give you an idea of the internal storage structure.
So if you make it past this:


$result = $client->getJobs(); // Or $client->__soapCall('getJobs'); i believe is the technically 'correct' route

without triggering a soap fault, the problem is later in the handling. Dump the $result to see exactly what it is:


var_dump($result);


It should tell you if its an object or string or array or whatever. My suspicion is it will be an array since there is no classmap on you're client indicating it should be an object.

Ty44ler
01-21-2010, 03:40 PM
There was no Soap Fault!


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


echo "<pre>\n";
var_dump($result);
echo "</pre>";
But there was an error...

Returns:


Warning: SoapClient::__soapCall() expects at least 2 parameters, 1 given in C:\xampp\htdocs\compliance\tester2.php on line 44

Fatal error: SoapClient::__soapCall() [<a href='soapclient.--soapcall'>soapclient.--soapcall</a>]: Invalid parameters in C:\xampp\htdocs\compliance\tester2.php on line 44

So it's saying it needs two parameters, but I didn't believe that there were any parameters needed?

Fou-Lu
01-21-2010, 04:32 PM
yes my bad, when you use the __soapCall, it expects to always have a argument.
So, with __soapCall like so:


$soapClient->__soapCall('mynoparamfunc', array());
$soapClient->__soapCall('myparamedfunc', array('oneparam'));

// with __call:
$soapClient->mynoparamfunc();
$soapClient->myparamedfunc('oneparam');


Although the __call approach is easier, its been deprecated in the api in favour of the __soapCall approach. I cannot tell you why they chose to do this.

On the plus side, you're above is looking good now, the errors are complaining about parameter conflictions, indicating that you're calls are now successful (though failing lol).

Ty44ler
01-21-2010, 04:49 PM
I really do appreciate you helping me out with this, you've been amazing just with what you've helped me out with so far even if there are still errors. I've gotten further now than I have on my own.


I took what you wrote, assuming that the one I needed was the with 'mynoparamfunc' since my function has no parameters. I placed it within my code like so:

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

but now, I get a SoapFault Exception...



Fatal error: Uncaught SoapFault exception: [HTTP] Not Found in C:\xampp\htdocs\compliance\tester2.php:47
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(47): SoapClient->GetJobs()
#3 {main}
thrown in C:\xampp\htdocs\compliance\tester2.php on line 47

Did I misunderstand the code or am I screwing something up?

Fou-Lu
01-21-2010, 05:04 PM
Nope, this is the same error I was getting when I couldn't actually attach to a soapserver.
Instead of using the wsdl, try non-wsdl mode instead. To me, it appears that the Service1.wsdl file is pointing to the incorrect location for where the services are being served from (http://sqlsvr1/RefrigerantComplianceService/Service1.asmx). You can also try to type that manually into you're browser to see if you get a soap response.
Non-wsdl mode would be like so:


$aOptions = array(
'location' => 'http://webpath/to/service',
'uri' => 'http://tempuri.org/'
);
$client = new SOAPClient(null, $aOptions);

You'll need to play with the location, to me it appears that the path (RefrigerantComplianceService/Service1.asmx) is invalid for the service. I cannot help you with the correct path I'm afraid, but since its internal you should be able to either browse it or find out the correct location. If this location is correct, I'll need to think about this a little more.

Ty44ler
01-21-2010, 05:14 PM
I may have messed you up, the address changed from sqlsrvr to refrigerantcompliance midway through this discussion. Sorry I didn't mention that...

But, the path seems correct:
http://s1.postimage.org/la5Dr.jpg (http://www.postimage.org/image.php?v=gxla5Dr)

I do believe that trying non-wsdl mode helped. It gave a different error as it said it did not recognize the value of the HTTP Header SOAPAction. Is that error due to the code or the address?

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:

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

Fou-Lu
01-21-2010, 05:31 PM
(Image is blocked by the work firewall from the looks of it)
Mkay, lets try a manual setting of the soap action:


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


That work? Looks to me like its the WSDL file causing the problems with incorrect targets.

Ty44ler
01-21-2010, 05:35 PM
(Image is blocked by the work firewall from the looks of it)
Mkay, lets try a manual setting of the soap action:


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


That work? Looks to me like its the WSDL file causing the problems with incorrect targets.

YES! That worked!!! No errors!!!!:thumbsup:

Wow, So now it has successfully connected and I should be able to print out the data from it? like the 'Description' or 'RequestNo' for example?

or am I getting ahead of myself?

Fou-Lu
01-21-2010, 05:41 PM
Yeah, use a var_dump($result); to see the structure.

Ok, the problem here is the WSDL file. I seem to recall that asp is quite smart in how it does this though, so check and see if a valid wsdl file is located here:


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


Type that in, see if you get a WSDL, and if you do, scroll down towards the bottom and check that these:


- <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>


Are pointing to the correct location (as this one above is the incorrect location).
Otherwise, you'll need to pass that soapaction all the time. Which sucks. If the wsdl is correct, you can just retarget it and put the client into wsdl mode again.

Ty44ler
01-21-2010, 06:05 PM
Yep, I typed that in the browser and the correct WSDL showed up and the url's at the bottom match correctly.

So, to put it back into WSDL mode I would do this:

$client = new SoapClient("http://refrigerantcompliance/RefrigerantComplianceService/Service1.asmx?wsdl");
$result = $client->__soapCall('GetJobs', array(), array('soapaction' => 'http://tempuri.org/GetJobs'));
Correct? that worked for me when I tested it out, just wanted to see if there was anything I didn't need.

THANK YOU SO MUCH BY THE WAY!!!

Fou-Lu
01-21-2010, 07:24 PM
Yep, if the WSDL mode is correct, it should provide you with the proper soapaction from this point. You shouldn't need to have the soapaction provided in the __soapCall anymore, so you can now call you're methods with:


$result = $client->__soapCall('methodname', array('anyargs1', 'anyargs2', [...]));



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum