Martin
Martin

Reputation: 2673

SOAP request by PHP

I have data:

POST /Reseller.asmx HTTP/1.1
Host: server.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://server/FunctionOnDemand"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthHeader xmlns="http://server/">
      <UserName>string</UserName>
      <Password>string</Password>
    </AuthHeader>
  </soap:Header>
  <soap:Body>
    <OrderServicesExport xmlns="http://server/" />
  </soap:Body>
</soap:Envelope>

I need to send soap request to "someURL?WSDL" using PHP.

Can anybody help?

Upvotes: 0

Views: 505

Answers (1)

Krish R
Krish R

Reputation: 22711

Hope it helps you,

1 Enable PHP extension. --enable-libxml

2 Enable SOAP support, configure PHP with --enable-soap .

Sample PHP code,

<?php

    $soapClient = new SoapClient("https://soapserver.example.com/blahblah.asmx?wsdl");

    // Prepare SoapHeader parameters
    $sh_param = array(
                'Username'    =>    'username',
                'Password'    =>    'password');
    $headers = new SoapHeader('http://soapserver.example.com/webservices', 'UserCredentials', $sh_param);

    // Prepare Soap Client
    $soapClient->__setSoapHeaders(array($headers));

    // Setup the RemoteFunction parameters
    $ap_param = array(
                'amount'     =>    $irow['total_price']);

    // Call RemoteFunction ()
    $error = 0;
    try {
        $info = $soapClient->__call("RemoteFunction", array($ap_param));
    } catch (SoapFault $fault) {
        $error = 1;
        print("
        alert('Sorry, blah returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.". We will now take you back to our home page.');
        window.location = 'main.php';
        ");
    }

    if ($error == 0) {       
        $auth_num = $info->RemoteFunctionResult;

        if ($auth_num < 0) {
            ....

            // Setup the OtherRemoteFunction() parameters
            $at_param = array(
                        'amount'        => $irow['total_price'],
                        'description'    => $description);

            // Call OtherRemoteFunction()
            $trans = $soapClient->__call("OtherRemoteFunction", array($at_param));
            $trans_result = $trans->OtherRemoteFunctionResult;
        ....
            } else {
                // Record the transaction error in the database

            // Kill the link to Soap
            unset($soapClient);
        }
      }
     }   
  }

 ?>

Basic Tutorial : http://www.sitepoint.com/web-services-with-php-and-soap-1/

More info: http://www.php.net/manual/en/book.soap.php

Ref: http://www.appsntech.com/2012/05/how-to-write-soap-web-service-using-php.html

Upvotes: 1

Related Questions