3

Here is the WSDL ...

I am using the SOAP Client in PHP with documentation HERE ...

Soap Call

$wsdl = 'https://api.krollcorp.com/EBusinessTest/Kroll.Dealer.EBusiness.svc/Docs?singleWsdl';

try {
    $client = new SoapClient($wsdl, array('soap_version' => SOAP_1_2, 'trace' => 1));
    // $result = $client->SubmitPurchaseOrder();
    $result = $client->__soapCall("SubmitPurchaseOrder", array());
} catch (SoapFault $e) {
    printf("\nERROR: %s\n", $e->getMessage());
}

$requestHeaders = $client->__getLastRequestHeaders();
$request = $client->__getLastRequest();
$responseHeaders = $client->__getLastResponseHeaders();
printf("\nRequest Headers -----\n");
print_r($requestHeaders);
printf("\nRequest -----\n");
print_r($request);
printf("\nResponse Headers -----\n");
print_r($responseHeaders);
printf("\nEND\n");

Output

ERROR: The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IEBusinessService/SubmitPurchaseOrder'.

Request Headers -----
POST /EBusinessTest/Kroll.Dealer.EBusiness.svc HTTP/1.1
Host: api.krollcorp.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.6.19
Content-Type: application/soap+xml; charset=utf-8; action="http://tempuri.org/IEBusinessService/SubmitPurchaseOrder"
Content-Length: 200


Request -----
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://tempuri.org/"><env:Body><ns1:SubmitPurchaseOrder/></env:Body></env:Envelope>

Response Headers -----
HTTP/1.1 500 Internal Server Error
Content-Length: 637
Content-Type: application/soap+xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 06 Sep 2017 12:42:57 GMT

END

Attempts

I am a beginner at using SOAP APIs.

I believe this is failing because SOAP 1.2 uses WsHttpBinding instead of BasicHttpBinding.

I am not sure how to set WS Addressing with the SOAP Client in PHP ...

ma77c
  • 1,052
  • 14
  • 31

3 Answers3

4

Below code is working for me.You can enable Ws-A Addressing and call soap method-

$client = new SoapClient("http://www.xyz.Services?Wsdl", array('soap_version'   => SOAP_1_2,'trace' => 1,'exceptions'=> false
    ));
    $wsa_namespace = 'http://www.w3.org/2005/08/addressing';
    $ACTION_ISSUE = 'http://www.xyx/getPassword';// Url With method name
    $NS_ADDR = 'http://www.w3.org/2005/08/addressing';
    $action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);

    $to = new SoapHeader($NS_ADDR, 'To', 'http://www.xyx.svc/Basic', false);
    $headerbody = array('Action' => $action,'To' => $to);
    $client->__setSoapHeaders($headerbody);


    //$fcs = $client->__getFunctions();
    //pre($client->__getLastRequest());
//pre($fcs);

$parameters=array('UserId'=>'12345678','MemberId'=>'123456','Password' => '123456','PassKey' => 'abcdef1234');
;
$result = $client->__soapCall('getPassword', array($parameters));//getPassword method name
print_r(htmlspecialchars($client->__getLastRequest()));// view your request in xml code

print_r($client->__getLastRequest());die; //Get Last Request

print_r($result);die; //print response
  • i have tried this but it is not working for bsestar getPassword. error = destination unreachable @Neeraj Yadav – shashikant kuswaha Dec 15 '18 at 15:57
  • 1
    can u please tell me which api u getting the error in get password. Actually i was also implemented this for BSE and working fine. @Shashikant – Neeraj Yadav Dec 19 '18 at 13:29
  • i have tried this-- url : http://bsestarmfdemo.bseindia.com/MFUploadService/MFUploadService.svc using soap client as well many other ways like nusoap in php but not succeded. – shashikant kuswaha Dec 19 '18 at 14:22
  • 1
    $client = new SoapClient("http://bsestarmfdemo.bseindia.com/MFUploadService?Wsdl", array('soap_version' => SOAP_1_2,'trace' => 1,'exceptions'=> false )); $wsa_namespace = 'http://www.w3.org/2005/08/addressing'; $ACTION = 'http://bsestarmfdemo.bseindia.com/2016/01/IMFUploadService/getPassword'; $NS_ADDR = 'http://www.w3.org/2005/08/addressing'; $action = new SoapHeader($NS_ADDR, 'Action', $ACTION, true); $to = new SoapHeader($NS_ADDR, 'To', 'http://bsestarmfdemo.bseindia.com/MFUploadService/MFUploadService.svc/Basic', false); – Neeraj Yadav Dec 20 '18 at 07:43
  • 1
    $headerbody = array('Action' => $action,'To' => $to); $client->__setSoapHeaders($headerbody); $fcs = $client->__getFunctions(); $parameters=array('UserId'=>BSEUserId,'MemberId'=>BSEMemberId,'Password' => BSEPassword,'PassKey' => rand(10000,99999)); $result = $client->__soapCall('getPassword', array($parameters)); – Neeraj Yadav Dec 20 '18 at 07:43
  • 1
    @sashi use both above comment in single function and pass ur bse auth like BSEUserId,BSEMemberId and BSEMemberId – Neeraj Yadav Dec 20 '18 at 07:44
  • i will try and let you know. – shashikant kuswaha Dec 20 '18 at 10:14
  • i have tested the code below https://stackoverflow.com/a/53866776/7820028 please have a look and also shared the reponse of error.--@neeraj – shashikant kuswaha Dec 20 '18 at 10:27
  • @NeerajYadav, it's works fine. Thanks a lot! – Edgar Leite Dec 14 '20 at 14:01
0

Dude, I totally feel your pain. I was able to get this to work but I don't think this is the right way, but it is pointing in the right direction. A caveat though, you have to know what namespace soap_client is going to assign to the addressing. Best way is just to capture the request XML and look for what namespace is attache to the addressing, and then pass it in. Below is my code with a default of 'ns2' for namespace, but you can't count on it for your example. Good Luck!

private function generateWSAddressingHeader($action,$to,$replyto,$message_id=false,$ns='ns2')
{
    $message_id = ($message_id) ? $message_id : $this->_uniqueId(true);
    $soap_header = <<<SOAP
        <{$ns}:Action env:mustUnderstand="0">{$action}</{$ns}:Action>
        <{$ns}:MessageID>urn:uuid:{$message_id}</{$ns}:MessageID>
        <{$ns}:ReplyTo>
          <{$ns}:Address>{$replyto}</{$ns}:Address>
        </{$ns}:ReplyTo>
        <{$ns}:To env:mustUnderstand="0">$to</{$ns}:To>
SOAP;
    return new \SoapHeader('http://www.w3.org/2005/08/addressing','Addressing',new \SoapVar($soap_header, XSD_ANYXML),true);
} 
Rick
  • 1
0

My solution is

  1. Send request using SoapUi
  2. Copy request http log from SoapUi screen ( Bottom of SoapUi program)
  3. Past that code into the PHP project as fallows

    $soap_request = '{copy that part from SoapUi http log}';

        $WSDL = "**wsdl adres**";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER,         false);
        curl_setopt($ch, CURLOPT_URL,            $WSDL);
        curl_setopt($ch, CURLOPT_FAILONERROR,    true);
        curl_setopt($ch, CURLOPT_HTTPHEADER,     Array(
            'Content-Type: application/soap+xml; charset=utf-8',
            'SOAPAction: "run"',
            'Accept: text/xml',
            'Cache-Control: no-cache',
            'Pragma: no-cache',
            'Content-length: '. strlen($soap_request),
            'User-Agent: PHP-SOAP/7.0.10',
        ));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_TIMEOUT,        30);
        curl_setopt($ch, CURLOPT_POSTFIELDS,     $soap_request);
        $response = curl_exec($ch);
        if (empty($response)) {
            throw new SoapFault('CURL error: '.curl_error($ch), curl_errno($ch));
        }
        curl_close($ch);