There is a wcf server and I am trying to connect it and send requests.
The code is :
$url = "http://serverip:8080/example.svc?wsdl";
$params = array(
'Username' => 'username',
'Password' => 'password'
);
$client = new SoapClient($url);
var_dump($client->__getTypes()); //it works
$result = $client->Login($params); //gives error
But everytime I am getting internal server error. I spend 5 days and searhed all the web and tried all different methods but I am always getting internal server error. Error is below :
protected 'message' => string 'The server was unable to process ...
private 'string' (Exception) => string '' (length=0) ...
If I use SOAP UI I can send and get data or if I call "$client->__getTypes()" from php server, I get types. But if I call implemented functions with PHP it doesn't work. Are there anyone to help me?
Thanks a lot,
Perhaps you should pass the parameters as object as in the following example
try {
$client = new SoapClient('http://serverip:8080/example.svc?wsdl');
$params = new stdClass();
$params->Username = 'Username';
$params->Password = 'Password';
$client->Login($params);
} catch (SoapFault $e) {
// error handling
}
Related
I am using Laravel 5.5 with the AWS SDK for laravel (https://github.com/aws/aws-sdk-php-laravel).
I'm trying to do a simple request to establish that I'm connecting correctly. I believe I have my credentials all set and nothing points to that as an error.
Here is the function in my laravel controller that is being called:
public function testData(Request $request) {
$sdk = new Sdk([
'endpoint' => 'http://localhost:80',
'region' => 'us-east-1',
'version' => 'latest'
]);
$dynamodb = $sdk->createDynamoDb();
$marshaler = new Marshaler();
$tableName = 'funTalkDataStorage';
$params = [
'TableName' => $tableName
];
try {
$result = $dynamodb->query($params);
} catch (DynamoDbException $e) {
echo "Unable to query:\n";
echo $e->getMessage() . "\n";
}
}
The table 'funTalkDataStorage' does exist out on AWS already where there are two records already.
The thing that I'm not understanding is why I'm getting the following error from Laravel:
Aws \ Api \ Parser \ Exception \ ParserException
Error parsing JSON: Syntax error
being thrown by :
aws\aws-sdk-php\src\Api\Parser\PayloadParserTrait.php
The error is originating from the line in my code:
$result = $dynamodb->query($params);
I've been digging through the sdk and searching the web and I'm just not getting where the issue is. Any help would be marvalous!
Ok. My issue was that i was using port 80. It should have been port 8000.
Thank you for taking the time to review my question.
I have been trying to implement the Citrix Go2Webinar Api and found this nice framework: https://github.com/teodortalov/citrix
I have successfully registered users, but I can't figure out how to get the response from the API.
public function user_registration($user, $webinar_id)
{
$client = new \Citrix\Authentication\Direct([$this->api_key]);
$client->auth($this->username, $this->password);
$webinar = new \Citrix\GoToWebinar($client);
$registration = array('firstName' => $user['first_name'], 'lastName' => $user['last_name'], 'email' => $user['email']);
$registrant = $webinar->register($webinar_id, $registration);
return $registrant;
}
The response I get looks like a bunch of protected variables. My question shouldn't I be able to call a method to get the formatted response which looks like what the Citrix API expects to return:
{
"registrantKey": 0,
"joinUrl": "string"
}
those methods are in consumer.php
$registrant = $webinar->register($webinar_id, $registration);
$myJoinUrl = $registration->getJoinUrl();
$myRegistrantKey = $registration->getId();
I connected to a SOAP server from a client and am trying to send form information back.
The connection works, but I have no idea how to send data back. I have received documentation ( -> http://s000.tinyupload.com/?file_id=89258359616332514672) and am stuck at the function AddApplication
This is the PHP code I've written so far. There is no form integration yet, only dummy data.
<?
$client = new SoapClient(
'https://wstest.hrweb.be/TvBastards/TvBastards/Job.svc?singleWsdl',
array(
'soap_version' => SOAP_1_1
)
);
$params = array(
'username' => 'XXX',
'password' => 'XXX',
'environmentKey' => 'XXX',
);
//Open session
try{
$token = $client->OpenSession($params);
}catch(SoapFault $ex){
echo "<pre>";
print_r($ex->detail->ExceptionDetail);
echo "</pre>";
}
//Add Application
try{
$resp = $client->AddApplication($params, ___THE_XML_SHOULD_BE_HERE___); // I have no idea how I can implement a XML file over here, and make this part work
}catch(SoapFault $ex){
echo "<pre>";
print_r($ex->detail->ExceptionDetail);
echo "</pre>";
}
//Close session
try{
$app = $client->CloseSession($token);
}catch(SoapFault $ex){
echo "<pre>";
print_r($ex);
echo "</pre>";
}`
The error I receive now is the following:
End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 156.
Which is understandable as I don't provide any XML.
I receive my token so the OpenSession works perfectly. As said, I'm completely stuck at the AddApplication function. This is my first encounter with a SOAP service, so every possible bit of explanation is highly appreciated.
Fixed it, and hopefully it can help out some others. I'll try and put it into steps.
define('SIM_LOGIN', 'LOGIN NAME HERE');
define('SIM_PASSWORD', 'LOGIN PASSWORD HERE');
define('ENV_KEY', 'ENVIRONMENT KEY HERE');
/*** login parameters ***/
$params = array(
'username' => SIM_LOGIN,
'password' => SIM_PASSWORD,
'environmentKey' => ENV_KEY,
);
/*** Set up client ***/
$client = new SoapClient(
__SOAP URL HERE__,
array(
'soap_version' => SOAP_1_1
)
);
After setting up the parameters and connecting to the client, we can start calling functions within the SOAP service. Every SOAP service will be different, so function names and parameters can be different. In below example I need to open a session to retrieve a token. This token is used in all the other functions, so this function is necessary. If something fails I call the "abort()" function.
try{
$token = $client->OpenSession($params);
}catch(SoapFault $ex){
abort();
}
If the token is received I call upon the function AddApplication. This expects the token parameter and an "object" (which is basically an STDClass).
I create an stdClass with all my data:
/*** Create stdClass with requested data ***/
$std = new stdClass();
$std->Firstname = $firstname;
$std->Lastname = $lastname;
$std->Birthdate = $birthdate;
$std->Phone = $phone;
$std->Email = $email;
Be sure to check camelcasing of names or capitals, as this makes all the difference.
Now we call upon the AddApplication function with parameters "token(string)" and "application(object)".
/*** AddApplication ***/
try{
$result = $client->AddApplication(array("token" => $token, "application" => $std));
}catch(SoapFault $ex){
abort();
}
If all goes well the data is stored on the external server and you receive a "success" message. It's possible that you receive a "fail" even without going into the SoapFault. Be sure to log both "$result" and "$ex", as a SOAP service can return a "Fail" but the try-catch sees this as a well formed result.
Last thing to do is close the session (and destroy the token)
/*** CloseSession ***/
try{
$app = $client->CloseSession($token);
}catch(SoapFault $ex){
abort();
}
If any questions, don't hesitate to ask them here, I'll be glad to help as I had such problems figuring this out.
I am executing following in my web-service file to get the sharepoint list data:
$authParams = array('login' => 'user', 'password' => 'pass');
/* A string that contains either the display name or the GUID for the list.
* It is recommended that you use the GUID, which must be surrounded by curly
* braces ({}).
*/
$listName = "TestList1";
$rowLimit = '150';
$wsdl = "http://192.168.1.197:5000/sharepoint/ListsWSDL.wsdl";
//Creating the SOAP client and initializing the GetListItems method parameters
$soapClient = new SoapClient($wsdl, $authParams);
$params = array('listName' => $listName, 'rowLimit' => $rowLimit);
//Calling the GetListItems Web Service
$rawXMLresponse = null;
try{
$rawXMLresponse = $soapClient->GetListItems($params)->GetListItemsResult->any;
}
catch(SoapFault $fault){
echo 'Fault code: '.$fault->faultcode;
echo 'Fault string: '.$fault->faultstring;
}
But it is going into the catch block with following error:
Fault code: HTTPFault string: Not Found
what is the problem. Thanks in advance.
Try http://[sharepoint site url]/_vti_bin/lists.asmx?WSDL for the wsdl,
but the actual webservice exists on http://[sharepoint site url]/_vti_bin/lists.asmx
This list of webservices has a page showing the url for each service.
I have a WCF Service written in .Net 4.0 that accepts two parameters. One is a complex type consisting of User, MerchantName, and Password, the second variable is an int. The service returns a third complex type.
It's structure looks like the following:
//*C# Code *
public sub AccountData Log(Login LoginData, int AccountID)
{
//do stuff here
}
Using SoapClient and removing the int AccountID from the C# service, I can pass the complex data in and parse through the complex data output succesfully. Adding the AccountID parameter, breaks the soap call. I can't seem to compound the variables into one array in a fashion that WCF will accept.
The question is how to form the array to pass in the call?
I have tried the following:
//****Attempt one *******
$login = array('MerchantName' => 'merchantA',
'User' => 'userA',
'password' => 'passwordA');
$account = '68115'; //(also tried $account = 68115; and $account = (int)68115;)
$params = array('LoginData' => $login, 'AccountID' => $account);
$send = (object)$params; //Have tried sending as an object and not.
$client = new SoapClient($wsdl);
$client->soap_defencoding = 'UTF-8';
$result = $client->__soapCall('Log', array($send);
var_dump($send);
echo("<pre>");
var_dump($result);
The latest attempt was to class the variables but I got stuck when tring to form into the $client call.
class LogVar
{
public $MerchantName;
public $User;
public $Password;
}
class AccountID
{
public $AccountID;
}
$classLogin = new LogVar();
$classLogin->MerchantName = 'merchantA';
$classLogin->User = 'userA';
$classLogin->Password = 'passwordA';
$classAccount = new AccountID();
$classAccount->AccountID = '68115';
//How to get to $client->__soapCall('Log', ???????);
P.S. I'm a .Net coder, please be kind with the PHP explanations... Also NuSoap didn't seem much better, however it may have undiscovered ways of dealing with complex types.
This worked for me with standard SoapClient:
$client = new SoapClient($wsdl, array('trace' => true));
$data = $client->Log(array('AccountID' => 23, 'LoginData' => array('User' => '123', 'Password' => '123', 'MerchantName' => '123')));
// echo $client->__getLastRequest();
var_dump($data);
You can display the last request XML and compare it with what a WCF client is generating. This is how I figured it out: I generated a WCF client, inspected the XML message generated by it and compared to $client->__getLastRequest.
Note: You can call the method by its name on a SoapClient rather than use $client->__soapCall('operationName')