SOAP call works in SoapUI but fails in PHP using soapclient - Object reference issue

不羁岁月 提交于 2019-12-04 20:30:34

You're probably right about the header being the cause, or at least part of it. I am not currently within easy reach of a soap server, but I hope the below can at least give some pointers.

There are two possibilities here: either the header should be included as a SoapHeader object, or you need to build your parameters array differently. I'll list both versions.

Either way, you can probably skip the __soapCall() method and use the magic method instead, since you appear to be using wsdl.

Parameters version (try this first)

If you're lucky, you just need to reformat the body in order to suit the given schema. It honestly kinda looks like that. Something like this:

$params = array(
    'request' => array(
        'Header' => array(
            'Token' => 'hello'
        ),
        'Parameters' => array(
            'DeviceID' => 12345,
            'SourceScreen' => 12345,
            'Language' => 'E',
            'LocalDateTime' => '2015-05-20T11:59:29.910Z',  
            'TicketID' => 12345,
            'PayScreenAttributeID' => 12345,
            'InputValue' => '123456789',
            'PaymentAmount' => 0,
            'POSReceiptCustomer' => '?',
            'POSReceiptMerchant' => '?'
        )
    )
);

$wsdl_path = "http://192.168.1.1/TestSite/TestService.asmx?wsdl";
$soapClient = new SoapClient($wsdl_path, array('trace' => 1));
$response = $soapClient->ProcessTransaction($params);

SoapHeader version

What you need to do if you actually do need a proper header is to create an header object and attach it to the client you've instantiated. Then, you can call the endpoint.

In order to do so you need to know the namespace, which should be called targetNameSpace in your schema. You'll also need to know the name, which you can see in e.g. SoapUI.

Finally, it should be enough to just supply the parameters straight away - no need to put them in a single-element array. So you end up with something like the below. With any luck, that may at least put you in the right direction. :)

// instantiate soap client
$wsdl_path = "http://192.168.1.1/TestSite/TestService.asmx?wsdl";
$soapClient = new SoapClient($wsdl_path, array('trace' => 1));

// create and attach a header
$header = new SoapHeader($namespace, $name, array('Token' => 'hello'));
$soapClient->__setSoapHeaders($header);

// call the endpoint
$response = $soapClient->ProcessTransaction($inputParams);
var_dump($response); // hopefully you get something back...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!