开发者

SOAP PHP calling .NET. No parameters

开发者 https://www.devze.com 2023-01-26 13:20 出处:网络
Folks, I\'m using SOAPClient in PHP to call a .NET webservice. All fine and dandy, right up to the point where I\'m passing parameters. The remote webservice makes a request to a listener.php file wh

Folks,

I'm using SOAPClient in PHP to call a .NET webservice. All fine and dandy, right up to the point where I'm passing parameters. The remote webservice makes a request to a listener.php file which processes the response, however at present it doesn't seem to be able to get the parameters... checking the request before it gets sent doesn't seem to show the parameters in the XML.

Can someone definitively show me how to pass parameters? So far I've seen about 3 different ways including, but not limited to the following:

$pCriteria->AuctionID = new SoapVar($auction_id, XSD_INT, 'xsd:int');

or:

$ar_bidupdate_params_total = array('AuctionID' => $auction_id,'parameter2... etc..)

or:

$ar_bidupdate_params = array( new SoapParam($auction_id, 'AuctionID'),

sample code also shows this being called in a variety of ways (from what I've seen around the web).

$info = $soapClient->__call("BidUpdate", array($pCriteria));

or

$info = $client->BidUpdate($pCriteria);

Question is, 1) how do I pass these parameters reliably using native SoapClient, and 2) What is the best way to do this?

Alternatively, if I can't get this to play ball I might just bui开发者_StackOverflowld the XML on the fly. If I do choose this approach, what is the best way to send the string of XML?


To justify your concerns: YES, working with the SoapClient can be frustrating. Mostly because of the documentation. Here's a piece of sample code for you that I got working for a project a while back, though. I ended up using this technique in a library for a payment gateway. I know this isn't exactly pretty with the dereferenced function call from a string name, but it does work.

$method = "ACTION";
$wsdl = "WSDLFILE.wsdl";
$parameters = array (
    'location'              =>  "http://url.com",
    'local_cert'            =>  "/full/path/to/CERTIFICATE.pem,"
    'passphrase'            =>  "TEST-PASSWORD",
    'use'                   =>  SOAP_ENCODED ,
    'connection_timeout'    =>  4,
    'user_agent'            =>  null
);
$client = new SoapClient( $wsdl, $parameters );
$response = $client->{$method}( $data );
var_dump( $response );

To elaborate, after you have your wsdl and certificate set up (if required), then the SoapClient creates on the fly a function (the $method) corresponding to what's in the WSDL, ie: for an action such as "Capture()" or "Authorize()". The client then handles the XML send/parse. Whether you use SOAP_ENCODED or not, and how you pass the parameters really depends on what's on the other end.

I've dealt with creating envelope XML manually, though, and I'd advise against it. As long as you get a good WSDL dump, which a .NET project will do automatically and shouldn't be a problem, it's a good way to avoid a maintenance nightmare if/when it gets changed/updated as opposed to having to go manually twiddle XML text.


1) how do I pass these parameters reliably using native SoapClient This is tough because PHP doesn't like to give very good debugging errors. Make sure you test out all your calls to make sure your timeout is setup properly(PHP just returns false on timeout errors) and that your parameters are correct. The only way to do this reliably is to make sure you know what does work for your system, and stay inside those parameters. Check all the different options (timeout, credentials, etc) and play around with them until you get something really solid.

2) What is the best way to do this? Both of your calls are correct syntax, and the parameter structure really isn't that complex, it's just getting something working first that's the hard part. My structure is normally something like: $opts = array(...options...); $client = new SoapClient('https://URL/WebAPI/WebAPI.asmx?WSDL', $opts);

$paramters = array('a_sUserID' => $un, 'a_sUserPass' => $pw, 'xmlBatch' => $createTicketXML);

Then call like:

$result = $client->call('GetAllMembers',$paramters);

And this is a normal loop I make on a successful result:

foreach ($result['GetMemberAllResult']['MemberData'] as $key => $value)
{
   //code 
}

The thing that helps me out the most though is I get everything setup using SoapUI (http://www.soapui.org/) then migrate everything to PHP. There you can run tests and figure out exactly what is happening in your calls using a tool that is made for SOAP.


Just to let you all know how we got on.. the problem I was having was due to a more complex type being defined, therefore it never entered the function as individual parameters, it entered the function as a class, this only happened when a 'classmap' was defined.

We realised that something extra needed to go on when attempting to consume the service via .NET - (MS tie everything up for you in Visual Studio) it became obvious that an extra class was passed as a parameter, and probably would have been obvious if we'd understood the WSDL a bit more.

$classmap = array('UpdateInfo' => 'UpdateInfo');

$server = new SoapServer("domain.com/Listener.wsdl", array('classmap' => $classmap, 'soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'uri' => 'http://tempuri.org/'));#

Parameters array are passed as normal. Thanks to both of you for the help, albeit not quite the direction I needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号