Trying to make a call to the below web service, is this the correct way to pass a token in the soap header, its returning an incorrect token response, but the token is correct when i use it with soap ui..?
$soapclient = new SoapClient('http://api.fm-
web.co.za/webservices/AssetDataWebSvc/DriverProcessesWS.asmx?WSDL');
$token = array('Token'=>'XXXXXX');
$header = new SoapHeader('ass','soapenv',$token,false);
$response = $soapclient->__soapCall('GetDriverList',array(''),NULL,$header);
var_dump($response);
after some messing around this worked.
$soapclient = new SoapClient('http://api.fm-
web.co.za/webservices/AssetDataWebSvc/DriverProcessesWS.asmx?WSDL');
//$token = array('Token'=>'XXXXXX');
$header = new
SoapHeader('http://www.omnibridge.com/SDKWebServices/AssetData',
'TokenHeader',array('Token'=>'XXXXXX'),false);
//$DriverID = 3;
$params = array('DriverID'=>'3');
$response = $soapclient-
>__soapCall('GetDriver',array($params),NULL,$header);
var_dump($response);
SoapHeader definition can be tricky especially if you're not familiar with SOAP.
My advise would be to use a WSDL to PHP generator that would provide you a SDK with the method to set any SoapHeader and particularly this SoapHeader.
You should try the PackageGenerator project which should provide you the SoapHeader methods within the ServiceType\Get instance you'll have to create. Take a look to the generated tutorial.php file.
Related
I use external libraries to communicate with external systems. Communication is via Soap.
I provide the library with a set of data in a simple way. She checks the data, sends the request, and receives the reply. Converts the response to its object and returns.
How can I access the SoapClient object without making changes to the external library?
For this object, I need the original data. Request, response, headers.
Is it possible to do?
EDIT:
A simple example of using one of the many external libraries:
class fedex {
public function trackShipment($number)
{
$trackRequest = new TrackServiceTrackRequest();
$trackRequest->WebAuthenticationDetail->UserCredential->Key = $this->getAccessNumber();
$trackRequest->WebAuthenticationDetail->UserCredential->Password = $this->getAccountPassword();
$trackRequest->ClientDetail->AccountNumber = $this->getAccountNumber();
$trackRequest->ClientDetail->MeterNumber = $this->getMeterNumber();
$trackRequest->SelectionDetails[0]->PackageIdentifier->Value = $number;
$request = new TrackServiceRequest();
return $request->getTrackReply($trackRequest);
}
}
$fedex = new fedex();
$result = $fedex->trackShipment('123456789');
How to get original xml with request and header that was sent by library without modifying it?
The TrackServiceRequest() object does not access the SoapClient() object.
I need to perform post request using using Symfony framework. I can see there is package Symfony\Component\HttpFoundation\Request for this purpose. But when I create post request it seems doens't really perform request and return object data
$response = Request::create(get_api_url().'test','POST', $params);
How can I permorm real post request?
You can use
use Symfony\Component\HttpClient\HttpClient;
$client = HttpClient::create();
$response = $client->request('POST', 'https://...');
More details you can find here
Is there a way using Guzzle in PHP that when I make a request to an API call that I can map my response to a Response object?
So instead of having to get the response data and then passing my array value as an argument, Guzzle can automatically resolve it to the required class?
In essence, this is what I am doing:
$client = new GuzzleHttp\Client();
$response = $client->request('myapi.users', 'GET');
$responseData = $response->getBody()->getContents();
$user = new User($responseData);
However I would like to try and avoid that boilerplate code by doing something like the following:
$client = new GuzzleHttp\Client();
$user = $client->request('myapi.users', 'GET');
Does Guzzle allow you to map response objects to Responses?
Thanks!
Nope, an HTTP Client (which Guzzle is) is not responsible for that. That's why there is not such a function there.
You can use Guzzle and your own object mapper, BTW, and create an SDK for the API you are using. Like the GitHub SDK, for example, that also uses Guzzle inside, but provides a specific interface for the domain.
I need to query a WCF service in PHP, so that it can return an XML object back to me.
Previously I was able to do this using the http request and post method
$url = 'http://localhost:49000/';
//create the httprequest object
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST, $options);
Using Soap. I can make a connection doing this:
// Create a new soap client based on the service's metadata (WSDL)
$client = new SoapClient("http://localhost:8731/FileUploadService?wsdl");
But how can I pass the XML object into the soap client and return a XML object.
If you really want to send a string containing the XML, you could use
$client->YourSoapMethodCall( new SoapVar($xmlString, XSD_ANYXML) ).
But it would be more convenient to feed parameters with an array or objects (which I use).
cf. http://andrecatita.com/code-snippets/php-soap-repeated-element-name/
I'm extremely new to SOAP and I'm trying to implement a quick test client in PHP that consumes a ASP.NET web service. The web service relies on a Soap Header that contains authorization parameters.
Is it possible to send the auth header along with a soap request when using WSDL?
My code:
php
$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL");
$service->AddPendingUsers($users, 3); // Example
webservice
[SoapHeader("AuthorisationHeader")]
[WebMethod]
public void AddPendingUsers(List<PendingUser> users, int templateUserId)
{
ateamService.AddPendingUsers(users, templateUserId, AuthorisationHeader.UserId);
}
How would the auth header be passed in this context? Or will I need to do a low lever __soapCall() to pass in the header? Also, am I invoking the correct soap call within PHP?
You should be able to create a header and then add it to the client so it is sent for all subsequent requests. You will probably need to change the namespace parameter.
$service = new SoapClient("http://localhost:16840/CTI.ConfigStack.WS/ATeamService.asmx?WSDL");
// Namespace Header Name value must-understand
$header = new SoapHeader('http://tempuri.org/', 'AuthorisationHeader', $value, false);
$service->__setSoapHeaders(array($header));
$service->AddPendingUsers($users, 3); // Example
More information here
$client = new SoapClient(PassportWebService);
$apiauth =array('userName'=>HeaderName,'password'=>HeaderPassport,'ip'=>$onlineip);
$authvalues = new SoapVar($apiauth, SOAP_ENC_OBJECT,'ReqHeader',"SoapBaseNameSpace");
$header = new SoapHeader("SoapBaseNameSpace","ReqHeader", $authvalues, true);
$client->__setSoapHeaders(array($header));