web services - PHP SoapClient - Unauthorized Operation Exception - Request formed properly? -


I am trying to reach a 3-party GPS tracking SOAP WebService to return the list of our company's vehicles . I'm looking through the documentation for the SoapClient object and I'm reading here many examples on stack overflow, but I'm still not sure how to do this operation. $ api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $ Service_url = http://api.remotehost.com/RemoteService.svc?wsdl

This is the service for which I am trying to access, is WSDL, I get GetVehicles I am trying to reach () method When I use a new client:

$ client = New SOAP client ($ service_url, array ('cache_wsdl' = & gt; 0));

I have $ client- & gt; I'm able to run __getFunctions (), which lists all the functions properly, however, when I try to use the GetVehicles method: $ codes = $ client- & Gt; GetVehicles ($ api_key); var_dump ($ vehicles);

I'm getting an "attempt to do unauthorized operation" error I'm not sure whether this request is made incorrectly, or if I'm reaching the wrong URL Am I really reaching this by using SOAD client or __doRequest methods of SOAP client what is happening? If you look at WSDL, you can see other action URLs for specific tasks, should I use those places?

To try and debug, I am using the program SoapUI, I enter the WSDL URL, and the program pulls in the function list and I can issue a request from there. When I request to use GetVehicles, I get the correct list results back, so I know that the authentication is not a problem.

  & lt; soapenv: envelope xmlns: soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: api = "http://api.remotehost.com" & gt; & Lt; Soapenv: header / & gt; & Lt; soapenv: body & gt; & Lt; API: GetVehicles & gt; & Lt; - Optional: - & gt; & Lt; API: APIKey & gt; Xxxxxxxxxxxxxxxxxxxxxxxx & lt; / API: APIKey & gt; & Lt; / API: GetVehicles & gt; & Lt; / soapenv: Body & gt; & Lt; / soapenv: envelope & gt;   

The correct vehicle number returns XML, I am doing the wrong, I am very confused, and I am running out of time to fulfill it. Can someone point me in the right direction and let me know how should I make this SOAP request? Any help is greatly appreciated. Thanks!

You must specify how to use the $ api_key value Is, like:

  $ client-> GetVehicles (array ('APIKey' => $ api_key));   

To add some details, here's your call:

  $ client- & gt; GetVehicles ($ api_key);   

does not tell the way to use the client $ api_key if you see the output of __getFunctions () You will see that GetVehicles takes a certain type of parameter structure:

  GetVehiclesResponse GetVehicles (GetVehicles $ Parameter)   

view this For what that parameter structure is, you must issue a __getTypes () call here the relevant line is: straight GetVehicles {string APIKey; }

This means that you want to pass your GetVehicles call in fact there is a structure with a member. Fortunately PHP is good and will accept an array with matching names.

A useful way to debug this is to use your calls as a proxy (if you're not on Windows, you can do something similar.) Load the Fiddler, then this way Build your SoapClient:

  $ opts = array ('proxy_host' = & gt; 'localhost', 'proxy_port' => 8888); $ Client = new sop client ($ wsdl, $ opts);   

Then whatever call you make, however the client will appear in Fiddler to check for you. For example, your original call appears in Fiddler, like this:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; SOAP-ENV: envelope xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: ns1 = "http://api.silentpassenger.com" & gt; & Lt; Soap-ENV: Body & gt; & Lt; Ns1 also: GetVehicles / & gt; & Lt; / SOAP-ENV: Body & gt; & Lt; / SOAP-ENV: envelope & gt;   

Given that your API API element was not present, you might have given a useful clue about the wrong things.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -