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.
Related
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
Currently i'm trying to build a little PHP - Soap Connector, which worked pretty good so far. But when i'm deploying my little script to my server, it won't work anymore and i have no clue, why.
I'm connecting in 2 different ways (by curling the SOAP WSDL Scheme, and saving it temporary in the script location, and creating from that a new SOAP Client, and creating a SOAP Client directly by using the SOAP WSDL Scheme URL):
$opts = array(
'http'=>array(
'user_agent' => 'PHP Soap Client'
)
);
$context = stream_context_create($opts);
// SOAP 1.2 client
$params = array (
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_2,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 30,
);
$curlStuff = curl_init($soapURL);
curl_setopt($curlStuff,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curlStuff,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curlStuff,CURLOPT_TIMEOUT,30);
$response = curl_exec($curlStuff);
$info = curl_getinfo($curlStuff);
if($response) {
file_put_contents("./tempSoapScheme.wsdl", $response);
}
$soapClient = new SoapClient(
'./tempSoapScheme.wsdl',
array(
'trace' => 1,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
$soapClientTwo = new SoapClient(
$soapURL,
array(
'trace' => 1,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
$result = $soapClient->myLoginMethod(
array(
'username' => 'my#email.example',
'password' => 'password'
)
);
As i said earlier - on my local machine it works like a charm, and everything is fine. The param "soapURL", which is not inside the script, is just the https path to my SOAP WSDL Scheme.
I've tried different options inside "$params" array, other curl setopt settings, but i can't make it work.
The response from both SoapClients:
SOAP-ERROR: Parsing WSDL: Couldn't load from '<MyURL>' : failed to load external entity "<MyURL>", which is pretty uncommon, because the CURL could save everything.
Do you have any suggestions for me?
EDIT - forgot the most important thing:
- The server, which should execute the script, has very strong firewall restrictions, and the SOAP URL Scheme is on another server (not the same). And i guess, that is the point, why it won't work, but i receive an answer from the Scheme by executing CURL.. So it's just SOAP?
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 really stuck in this, and need expert help. Let me explain what I am trying achieve and the setup. I had a script which posts over a https form using Zend_Http_Client. On the server setup I have tor & privoxy running. Everything just worked fine, but now I need to make the code more scalable by running multiple instances of tor & privoxy on the same server.
Hence I shifted the Adapter for Zend from Zend_Http_Client_Adapter_Curl to Zend_Http_Client_Adapter_Proxy . But after changing the adapter I have bumped into a strange error which says - 400 Invalid header received from client and when I dump the object of Zend client, I see the following -
MyWebClientResponse::__set_state(array(
'json' => NULL,
'version' => '1.1',
'code' => 400,
'message' => 'Invalid header received from client',
'headers' =>
array (
'Proxy-agent' => 'Privoxy 3.0.19',
'Content-type' => 'text/plain',
'Connection' => 'close',
),
'body' => 'Invalid header received from client.
',
))
I do not understand what is that I am doing wrong. The code is done in Yii Framework so it is hard to share all the classes and Models, but I am sharing the main parts of the code, which are responsible for this -
$client = MyWebClient::factory();
$adapter = $client->getAdapter();
$adapter->setConfig(array('timeout' => 120,
'proxy_host' => 'localhost',
'proxy_port' => 8124
));
$client->setAdapter($adapter);
$client->setCookieJar(true);
$client->setParameterPost(array(
'name' => 'firstname',
'password' => 'password,
'login' => 'home'
));
$response = $client->setUri('https://www.domain.com/post.php')->requestApi('POST', false);
Here's the constructor of the class MyWebClient, just in case it it required, all other methods are standard.
static public function factory($new = false)
{
if (!isset(self::$client))
{
self::$client = new MyWebClient();
self::$client->setConfig(array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
// 'proxy_host' => 'localhost',
// 'proxy_port' => 8118,
'persistent' => false,
'timeout' => 120
));
}
return self::$client;
}
The headers are being set in the requestAPI method and the snippet is -
$headers = array(
'X-PHX' => 'true',
'X-Requested-With' => 'XMLHttpRequest',
'Referer' => 'https://domain.com/index.html',
'User-Agent' => self::getRandomUserAgent()
);
$this->setHeaders($headers);
I would really appreciate help in this regard. Think it's privoxy which is not letting go the request out of the server.
Sachin
Looks like you may need to wrap the user-agent with quotes. Try this when setting the headers and see if that fixes the problem.
$headers = array(
'X-PHX' => 'true',
'X-Requested-With' => 'XMLHttpRequest',
'Referer' => 'https://domain.com/index.html',
'User-Agent' => "'".self::getRandomUserAgent()."'"
);
$this->setHeaders($headers);
Finally I decided to use the native cURL library and the cookieJar which comes with it. It worked like expected.
Cheers,
Sachin
i am trying to calling .net webservice in php
below is my code.
<?php
$client = new SoapClient("http://test.etech.net/PanelIntegration/PanelIntegration.asmx?wsdl");
<?php
$sh_param = array(
'Username' => 'IntegratorLPI',
'Password' => 'password531');
$headers = new SoapHeader('http://wms.etech.net/', 'UserCredentials', $sh_param);
$client->__setSoapHeaders($headers);
$params = array('CustomerName' => 'Mr Smith','ContactMobileNo' => '01237 376347',
'AddressLine1' => '33 Amblecote Road',
'AddressTown' => 'Cambridgeshire',
'AddressPostCode' => 'NW23 6TR',
'VendorAddressLine1' => '80 Norton Road',
'VendorAddressTown' => 'Hickley ',
'VendorAddressCounty' => 'Cambridgeshire',
'VendorAddressPostCode' => 'NW23 2AQ',
'RegionalOfficeID' => '3',
'ExternalNotes' => 'Case Accepted',
'UPRN' => '',
'InstructionTypeID' => '2',
'PropertyTypeID' => '11',
'PropertyTenure' => '2',
'SurveyorID' => '23',
'RRN' => '0240-9002-0391-3520-0020',
'NewInstruction'=> 'true',
'StatusID' => '1'
);
$result = $client->__soapCall("UpdateInstruction", $params );
print_r( $result);
?>
i have got this error
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in C:\xampp\htdocs\test2.php:33 Stack trace: #0 C:\xampp\htdocs\test2.php(33): SoapClient->__soapCall('UpdateInstructi...', Array) #1 {main} thrown in C:\xampp\htdocs\test2.php on line 33
You probably need to send something like:
$result = $client->__soapCall("UpdateInstruction", array('Instruction' => $params );
Where Instruction is the name of the object that you are passing.
It looks like a NullReferenceException was thrown on the server side. So, it's a matter of the parameters to whatever function is occurring on the server side generating that error.
Regardless of why, per best practices, this is an error in the .NET service. The NullReferenceException should really be replaced with something more specific.
Can you get in touch with whomever wrote the service to get more information to troubleshoot? It's quite possible that you have a parameter misnamed in your $params array, but you're probably going to need some help from the service writer.