Clicky

Hi

I am new to Soap and WSDL etc.

I am trying to make a client connection to a remotely hosted WSDL using PHP, my code is quite short and simple as follows:

$client = new nusoap_client('url removed','wsdl');
$result = $client->call('MemberDetails', array('DetailCode' => 'Surname','DetailValue' => 'Brown'));

When running the script I get a fault returned from the remote server, it says that "Request" is missing.

Just to confirm... MemberDetails is the name of the function to call and this is correct as if I change it to something else and run the script then it throws an error saying what I have typed is not valid, so the MemberDetails part is defiantly working. The DetailCode and DetailValue are also correct as once again if I miss them out or change them it doesn't work.

This is what the XML request is supposed to look like when it gets sent over to the remote server:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<mgns1:MemberDetails xmlns:mgns1="url removed">
  <mgns1:Request>
    <mgns1:RequestDetailArray>
      <mgns1:DetailItem>
        <mgns1:DetailCode>Surname</mgns1:DetailCode>
        <mgns1:DetailValue>Brown</mgns1:DetailValue>
      </mgns1:DetailItem>
    </mgns1:RequestDetailArray>
    <mgns1:RequestId>Testing Web Service</mgns1:RequestId>
    <mgns1:RequestType>Member Details</mgns1:RequestType>
  </mgns1:Request>
</mgns1:MemberDetails>

Mine however only has the following XML:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<mgns1:MemberDetails xmlns:mgns1="url removed">
</mgns1:MemberDetails>

From the above it is clear that "Request" is missing, I just don't know where or how I add this to my PHP code.

Does this make any sense to anyone?

Thanks

Daz

asked 07/15/2011 08:43

DAZTOMKINS's gravatar image

DAZTOMKINS ♦♦


9 Answers:
i am using curl for this kind of requests and i can post my custom xml to the service. it's preaty easy and relaiable.

I tryed also with the nusoap but failed to make it work

hope this helps

link
racmail2001's gravatar image

racmail2001

here is a sample code to get you started
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
<?php

$post_string = "<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<mgns1:MemberDetails xmlns:mgns1="url removed">
  <mgns1:Request>
    <mgns1:RequestDetailArray>
      <mgns1:DetailItem>
        <mgns1:DetailCode>Surname</mgns1:DetailCode>
        <mgns1:DetailValue>Brown</mgns1:DetailValue>
      </mgns1:DetailItem>
    </mgns1:RequestDetailArray>
    <mgns1:RequestId>Testing Web Service</mgns1:RequestId>
    <mgns1:RequestType>Member Details</mgns1:RequestType>
  </mgns1:Request>
</mgns1:MemberDetails>
";

$url = "http://url.wsdl";
$header[]='Content-Type: text/xml; charset="UTF-16"';
$header[]="Content-length: ".strlen($post_string);

$tuCurl = curl_init(); 
curl_setopt($tuCurl, CURLOPT_URL, $url); 
//curl_setopt($tuCurl, CURLOPT_PORT , 59101); // for custom port request
curl_setopt($tuCurl, CURLOPT_VERBOSE, 0); 
curl_setopt($tuCurl, CURLOPT_HEADER, 0); 
curl_setopt($tuCurl, CURLOPT_POST, 1); 
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $post_string); 
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, $header); 

//var_dump($ch);
$data = curl_exec($tuCurl); 
$xml = simplexml_load_string($data);

echo"<pre>";
print_r($xml)
echo"</pre>";
?>
link
racmail2001's gravatar image

racmail2001

Hi racmail2001

Thank you for the suggestion of using curl

I have tried your sample but I get a completely blank white page.

Any ideas?

Thanks

Daz
link
DAZTOMKINS's gravatar image

DAZTOMKINS

did you changed the url at line 18? $url = "http://url.wsdl";
link
racmail2001's gravatar image

racmail2001

Yes I did
link
DAZTOMKINS's gravatar image

DAZTOMKINS

if I print_r the $data variable then I get the following response:

HTTP ERROR: 404 Not Found
link
DAZTOMKINS's gravatar image

DAZTOMKINS

please post the code. from the header it's seams that the wdsl service it's not responding or your link it's wrong
link
racmail2001's gravatar image

racmail2001

Hi, here is the code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
$post_string = '
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:staw="url hidden">
   <soapenv:Header/>
   <soapenv:Body>
      <staw:MemberDetails>
         <staw:Request>
            <staw:RequestDetailArray>
               <staw:DetailItem>
                  <staw:DetailCode>Surname</staw:DetailCode>
                  <staw:DetailValue>Brown</staw:DetailValue>
               </staw:DetailItem>
            </staw:RequestDetailArray>
            <staw:RequestId>Testing Web Service</staw:RequestId>
            <staw:RequestType>Member Details</staw:RequestType>
         </staw:Request>
      </staw:MemberDetails>
   </soapenv:Body>
</soapenv:Envelope>
';

	$header[]='Content-Type: text/xml; charset=UTF-8';
	$header[]='Accept: text/xml';
	$header[]='Cache-Control: no-cache';
	$header[]='Pragma: no-cache';
	$header[]='Content-Length: '.strlen($post_string);

	$tuCurl = curl_init();
	curl_setopt($tuCurl, CURLOPT_URL, "url hidden");
	curl_setopt($tuCurl, CURLOPT_PORT, 6060);
	curl_setopt($tuCurl, CURLOPT_POST, true);
	curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $post_string);
	curl_setopt($tuCurl, CURLOPT_HTTPHEADER, $header);

	$data = curl_exec($tuCurl);

	print_r($data);
link
DAZTOMKINS's gravatar image

DAZTOMKINS

Got it working, thanks for your help.
link
DAZTOMKINS's gravatar image

DAZTOMKINS

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

Asked: 07/15/2011 08:43

Seen: 630 times

Last updated: 08/12/2011 10:43