Sending a Soap Header with a WSDL Soap Request with PHP - php

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));

Related

How to globally override the SoapClient class?

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.

passing token in soap header php

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.

how to access .net webservice classes with php?

I have a .net web service which provide multiple methods and public classes.
I want to use these classes in php.
How can I do it?
this is my web service: http://10.2.3.74/AdaptorRepeater/BillPatientService.asmx?WSDL
for example I want access to AdmissionVO class and its properties
$client = new soapclient('http://10.2.3.74/AdaptorRepeater/BillPatientService.asmx?WSDL');
$header = new SoapHeader('http://sepas.behdasht.gov.ir/','HeaderMessageVO',$HeaderMessageVO,false);
$client->__setSoapHeaders($header);
$send = $client->SavePatientBillSecure($params);
I want for example this :
$client->AdmissionVO->MedicalRecordNumber = '1234';
Using SOAP Call You can access any Dot.Net Web service
You need to have Dot net web service WSDL path
now
<?php
//turn off WSDP caching if not in a production environment
$ini = ini_set("soap.wsdl_cache_enabled","0");
//instantiate the SOAP client
$client = new SoapClient("http://example.com/dotnet.asmx?WSDL");
echo $client->GetAllContactNames()->GetAllContactNamesResult;
//...optional additional code goes here...
?>

SOAP equivilent

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/

SOAP Authorization

The web service I'm trying to consume has such a WSDL file: http://dgpysws.teias.gov.tr/dgpys/services/EVDServis?wsdl
I'm trying to consume "setIkiliAnlasma" service, however accessing that service requires authentication. I have my credentials and when I make a SOAP call to login service it authenticates my credentials.
And as expected, when I call "setIkiliAnlasma" service I get an Authorization error. What is the method to combine authorization supplied by login call with the main service I need to consume?
By the way the programming language I'm usign is PHP and the native SoapClient functions: http://www.php.net/manual/en/class.soapclient.php
Here is an example of using the SOAPClient in PHP with authentication - you just need to adapt it to the WSDL you are using ->
// Setting "trace" will allow us to view the request that we are making, after we have made it.
$objClient = new SoapClient("http://www.somewhere.com/wsdls/some.wsdl", array('trace' => true));
// These parameters satisfy this specific remote call.
$arrParameters_Login = array('username' => 'username', 'password' => 'password');
// Invoke the remote call "login()".
$objLogin = $objClient->login($arrParameters_Login);
// Grab session ID that this remote call will provide.
$strSessionID = $objLogin->loginReturn->sessionId;
You will then need to use the sessionid / session code that is sent to you in the login response - maybe in a header - its specific to each WSDL.
try to use this way to authenticate when calling the soap client url :
http://username:password#domain.com/

Categories