4

I am a Beginner of soap, How do i send soap request? i searched in google and tried different methods but sadly it didn't worked for me.

i really appreciated your help.

here's the sample request that i should send:

POST /Universal/WebService.asmx HTTP/1.1
Host: www.sample.com
Content-Type: text/xml;charset="utf-8"
Content-Length: length
SOAPAction: https://www.sample.com/Universal/WebService.asmx/Request

<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:xsi="http://wwww.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Request xmlns="https://www.sample.com/Universal/WebService.asmx">
<ID>CPHK01</ID>
<UID>TEST</UID>
<PWD>TEST</PWD>
<target_mpn>09183530925</target_mpn>
<amount>115</amount>
<ref_no>20060830143030112</ref_no>
<source_mpn>67720014</source_mpn>
</Request>
</soap:Body>
</soap:Envelope>

here's the response:

 HTTP/1.1 200 OK
 Content-Type: text/xml; charset=utf-8
 Content-Length: length

 <?xml version = "1.0" encoding="utf-8"?>
 <soap:Envelope xmlns:xsi="http://wwww.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
 <RequestResponse xmlns="https://www.sample.com/Universal/WebService.asmx">
 <RequestResult>
 <Ref_no>20060830143030112</Ref_no>
 <StatusCode>101</StatusCode>
 </RequestResult>
 </RequestResponse>
 </soap:Body>
 </soap:Envelope>
MrCode
  • 63,975
  • 10
  • 90
  • 112
lgDroidZ
  • 43
  • 1
  • 1
  • 6
  • 3
    My main advice regarding `SOAP` is **Don't drop it!**. *[Sorry, couldn't resist trolling :).]* – CodeAngry Jul 04 '13 at 03:02
  • possible duplicate of [SOAP request in PHP with CURL](http://stackoverflow.com/questions/7120586/soap-request-in-php-with-curl) - and some others. Please use the search before asking a question. – hakre Jul 04 '13 at 16:13
  • @hakre **likes** to drop the `SOAP` – Jimbo Jul 04 '13 at 16:21
  • And then slide on it through the bathroom like skating on ice. – hakre Jul 04 '13 at 16:22

1 Answers1

4

PHP has a native SoapClient class. The constructor takes the WSDL as an argument. This is preferred to cURL because the SoapClient handles all of the SOAP intricacies and it allows you to deal with native objects and arrays and removes the need to manually build the SOAP envelope and XML.

try {
    $client = new SoapClient('https://www.sample.com/Universal/WebService.asmx?wsdl');
    $response = $client->Request(array(
        'ID' => 'xxxx',
        'UID' => 'xxxx',
        'PWD' => 'xxxx',
        'target_mpn' => 'xxxx',
        'amount' => 'xxxx',
        'ref_no' => 'xxxx',
        'source_mpn' => 'xxxx'
    ));

    print_r($response); // view the full response to see what is returned

    // or get the response properties:
    echo $response->RequestResult->Ref_no;
    echo $response->RequestResult->StatusCode;

} catch (Exception $e) {
    echo $e->getMessage();
}
MrCode
  • 63,975
  • 10
  • 90
  • 112
  • I'm getting this error McCode : SOAP-ERROR: Parsing WSDL: Couldn't load from – lgDroidZ Jul 04 '13 at 08:40
  • Did you update the wsdl in the code? check it in your browser to see if it's reachable. – MrCode Jul 04 '13 at 08:41
  • i don't know how to check if it's reachable MrCode. i have no experience about soap or wsdl, i just studying by my self. i appreciate your help – lgDroidZ Jul 04 '13 at 08:48
  • Just try to view the WSDL link in your browser, like a web page. This should give you an idea if it's reachable. Example https://www.sample.com/Universal/WebService.asmx?wsdl (change sample.com to yours) – MrCode Jul 04 '13 at 08:49
  • Yes but did you test it in your browser by trying to navigate to it? – MrCode Jul 04 '13 at 08:53
  • It is not reachable MrCode. i try to navigate in a browser. – lgDroidZ Jul 04 '13 at 08:55
  • you will have to contact whoever owns the server and ask them why it's unreachable. – MrCode Jul 04 '13 at 08:56
  • Ok tnx MrCode. i think my code before is working the problem is the server, it's not reachable. thanks MrCode – lgDroidZ Jul 04 '13 at 09:01
  • Yes, I agree, it's the server that's the problem. – MrCode Jul 04 '13 at 09:01