i want to send a below xml request to the server which is sending ok by using soap UI but not in php:
<ns:AgentLogin>
<ns:AgentLoginRQ>
<ns:Authentication>
<ns:DBName>************</ns:DBName>
<ns:IP>************</ns:IP>
</ns:Authentication>
<ns:AgentABTA>************</ns:AgentABTA>
<ns:UserName>************</ns:UserName>
<ns:Password>************</ns:Password>
</ns:AgentLoginRQ>
</ns:AgentLogin>
i create soap client like this
$client = new \SoapClient("https://digicom-poc-ota.inspiretec.com/TravelinkCEService.svc?wsdl");
which is ok and then create soap call function like this
$data = array('AgentABTA'=>'DIGICOM_POC_DEMO'
,'UserName'=>'************'
,'Password'=>'************'
,'Products'=>'************'
);
$result = $client->__soapCall('AgentLogin',$data);
__soapcall give me error of empty request body.
Hope this might help you out:
$client = new \SoapClient("your_wsdl_link", [
'trace' => true
]);
$params = [
'AgentLoginRQ' => [
'DBName' => 'DATABASE_NAME',
'AgentABTA' => '****',
'UserName' => '****',
'Password' => '********',
'Products' => '',
]
];
$result = $client->YourFunction($params);
This is surely because of the array data structure which is incorrect according to the WSDL. You should definitively use a WSDL to php generator which is nowadays common. It helps structuring the request data and easily handle the response all with an OOP approach.
You should take a look to the PackageGenerator project which could really help you deal with this SOAP Web Service.
Related
I currently have a vb.net ASMX web service hosted on IIS along with a PHP page which is calling the web service via a SoapClient.
I need to authenticate the webservice against ActiveDirectory and i figured the easiest way to do this would be to enable Digest Authentication on IIS and allow the user to enter their AD username/password into the PHP page and send this authentication in the SoapHeaders.
I am not really quite sure how to go about this, especially when trying to contact the WSDL (which is also behind the Digest Authentication).
Any help would be appreciated.
Thanks
EDIT: What i've tried:
SERVICE_URL points to http://mypage/service.asmx?wsdl
Attempt 1: User and Pass as MD5
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'realm' => 'myrealm',
'login' => $_SESSION['authUser'],
'password' => $_SESSION['authPass']
);
try { $client = new SoapClient(SERVICE_URL, $options); }
Attempt 2: Auth is the 'user':'realm':'pass' as MD5:
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'login' => $_SESSION['auth']
);
try { $client = new SoapClient(SERVICE_URL, $options); }
You can add headers to your soap client using SoapHeader() class/object (SoapHeader() documentation) and soap object operator __setSoapHeaders() (__setSoapHeaders() documentation).
Your request would look something like this:
<?php
$options = array(
'authentication' => SOAP_AUTHENTICATION_DIGEST,
'realm' => 'myrealm',
'login' => $_SESSION['authUser'],
'password' => $_SESSION['authPass']
);
try {
$client = new SoapClient(SERVICE_URL, $options);
// create and populate header array
$headers = array();
$headers[] = new SoapHeader('MYNAMESPACE',
'authentication',
'SOAP_AUTHENTICATION_DIGEST');
$headers[] = new SoapHeader('MYNAMESPACE',
'realm',
'myrealm');
$client->__setSoapHeaders($headers); // set headers
$client->__soapCall("echoVoid", null); // make soap call
}
?>
I need to generate following XML Soap request in PHP:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns1:SomeRequest enddate="01-01-2018 00:00:00" authCode="exampleexample">
<ns1:status>STATUS1</ns1:status>
<ns1:status>STATUS2</ns1:status>
</ns1:SomeRequest>
</soapenv:Body>
</soapenv:Envelope>
I'm trying like that:
$this->client = new SoapClient($this->wsdlUrl, [
'trace' => true,
'exception' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
]);
$parameters = [
'authCode' => 'exampleexample',
'enddate' => '01-01-2018 00:00:00',
'status' => ['STATUS1', 'STATUS2']
];
$response = $this->client->SomeSimpleMethod($parameters);
And receive Array to string conversion error.
When I'm trying pass status as string, like that:
$parameters = [
'authCode' => 'exampleexample',
'enddate' => '01-01-2018 00:00:00',
'status' => 'STATUS1'
];
Then everything works fine.
The best way is to use a WSDL to PHP generator as you won't wonder how to correctly construct the request. As it is not always straightforward to do so, using the generated classes to construct the request and to send it, you will easily send the request and handle the response using the OOP approach.
Try the PackageGenerator project which is best suited to generate a PHP SDK from any SOAP WSDL.
Having difficulties authorizing php SoapClient with MS Dynamic Great Plains. I can connect through SoapUI. However, it only successfully connects on 3rd attempt. Also, the auth token progressively gets longer. See pastebin link below.
I made use of the following package (https://github.com/mlabrum/NTLMSoap) to setup a NTLM stream, but it doesn't seem to be sending a correct token. The token length is shorter than what is sent through SoapUI.
$wsdlUrl = 'http://example.org:48620/Metadata/Legacy/Full/DynamicsGP.wsdl';
$options = [
'ntlm_username' => 'Domain\username',
'ntlm_password' => 'password'
];
$soapClient = new \NTLMSoap\Client($wsdlUrl, $options);
$params = array(
criteria => array(
'ModifiedDate' => array(
'GreaterThan' => '2016-04-18',
'LessThan' => '2016-04-19'
)
),>
'context' => array(
'OrganizationKey' => array(
'type' => 'CompanyKey',
'Id' =
)
)
);
$soapClient->__setLocation('http://example.org:48620/DynamicsGPWebServices/DynamicsGPService.asmx');
$response = $soapClient->GetPurchaseOrderList(array($params));
I had to set use ___setLocation() because client was being forwarded to http://localmachine:48620/DynamicsGPWebServices/DynamicsGPService.asmx
I have been trying to get Charles Web Proxy to work to show the actual the request/response, buts its crapped out on me.
This is the SoapUI output. http://pastebin.com/7zg4E3qD
I faced with very strange issue when tried to use PHP SoapClient for this service http://bws.neteven.com/NWS/2.
I have to setup an authentication header. Request body should be empty. The code, which I used is below:
$client = new SoapClient("http://bws.neteven.com/NWS/2", array("trace" => 1, "exception" => 1));
$auth = array(//the params are not valid of course
'Method' => 'TestConnection',
'Login' => 'login',
'Seed' => 'seed',
'Stamp' => 'stamp',
'Signature' => 'signature'
);
$client->__setSoapHeaders(new SoapHeader('auth', 'AuthenticationHeader', $auth));
$client->__soapCall('TestConnection',array(null));
After that I used $client->__getLastRequest() to see what is final XML of the request. However I can see that the header and body params were not setup properly.
$client->__getLastRequest() outputs plain text like this:
MethodTestConnectionLoginloginSeedseedStampstampSignaturesignature
Which doesn't look like valid XML. So of course I get SoapFault exception with the text "Body must be present in a SOAP envelope".
Does anybody knows why header and body are not wrapped by required XML tags?
Any issue in the code? Because I saw lots of examples of PHP SoapClient usage with the same approach. In addition I tried a few test WSDL services and had valid requests and responses there.
Could it be a problem of provided WSDL schema?
Or a problem of my server configuration? I use PHP 5.6.3, php_soap extension is enabled.
Hope you guys can help me. Any your thoughts would be really appreciated.
Thank you.
The code example I found has a different URL...
http://bws.neteven.com/NWS/2 vs http://ws.neteven.com/NWS
$client = new SoapClient("http://ws.neteven.com/NWS", array("trace" => 1, "exception" => 1));
$auth = array(//the params are not valid of course
'Method' => 'TestConnection',
'Login' => 'login',
'Seed' => 'seed',
'Stamp' => 'stamp',
'Signature' => 'signature'
);
$client->__setSoapHeaders(new SoapHeader('auth', 'AuthenticationHeader', $auth));
$client->__soapCall('TestConnection',array(null));
Also, you can call methods like this without using __soapCall (even though it would be doing the same thing).
$result = $client->echo(array("EchoInput" => "ReturnMe"));
var_dump($result->EchoOutput);
$result = $client->TestConnection();
var_dump($result->TestConnectionResult);
I am using the following php script in mule. When i am running this php file individually(through wamp) i am able to get the required output.
<?php
$client1=new SoapClient('example/v2_soap?wsdl', array('trace' => 1, 'connection_timeout' => 120));
$username = '******';
$password = '******';
//retreive session id from login
$session = $client1->login(
array(
'username' => $username,
'apiKey' => $password,
)
);
$result= $client1->catalogProductInfo(
array(
'sessionId' => $session->result,
'productId' => 1,
)
);
print_r($result);
return $result;
?>
But i want to run the following script through mule. So when i am running it through mule i am getting the following error.
Root Exception stack trace:
com.caucho.quercus.QuercusErrorException: eval::5: Fatal Error: 'SoapClient' is an unknown class name.
at com.caucho.quercus.env.Env.error(Env.java:4480)
at com.caucho.quercus.env.Env.error(Env.java:4399)
at com.caucho.quercus.env.Env.createErrorException(Env.java:4130)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
It says SoapClient is an unknown class. What is the problem here?
Do i have to include some SoapClient here? If so where can i find it. Please help!!
I'm not sure if mule supports php extensions, but that's what it seems by the error. You could try downloading nusoap into your project,
which doesn't require any php extension. The syntaxis is a little bit different though, but shouldn't be harder to adapt your code.
For what it's worth, this is a simple example of a soap request using nusoap (taken from here http://www.richardkmiller.com/files/msnsearch_nusoap.html):
require_once('nusoap/lib/nusoap.php');
$request = array('Request' => array(
'AppID' => 'MSN_SEARCH_API_KEY',
'Query' => 'Seinfeld',
'CultureInfo' => 'en-US',
'SafeSearch' => 'Strict',
'Flags' => '',
'Location' => '',
'Requests' => array(
'SourceRequest' => array(
'Source' => 'Web',
'Offset' => 0,
'Count' => 50,
'ResultFields' => 'All'))));
$soapClient = new soapclient("http://soap.search.msn.com/webservices.asmx?wsdl", false);
$result = $soapClient->call("Search", $request);
print_r($result);
I hope it helps.
I understand there seems to be a problem with running the soap client inside quercus (rather than Mule).
However instead of focusing on it I would suggest to take a look to the CXF client and the Web services consumer. You are running inside of Mule a powerful opensource ESB, there is no need to write a php script to consume a service, you have all that functinality already present.