Python WSDL function parameters are not accepted - php

I can send function arguments to a SOAP client in PHP like this (searchLinks is a method name):
$client = new SoapClient("https://linksearch.api.cj.com/wsdl/version2/linkSearchServiceV2.wsdl", array('trace'=> true));
$results = $client->searchLinks(array("developerKey" => $developerKey,
"token" => '',
"websiteId" => $websiteId,
"advertiserIds" => 'joined'));
If I want to do the same thing in Python, how can I do this? This is the present code:
server=WSDL.Proxy(url)
results=server.searchLinks({'developerkey':dev_key,'token':'','websiteId':website_id,'advertiserIds':'joined'})
When I try to run this Python script, it throws errors. Why is it not taking function parameters like in PHP?

Which library are you using,
Assuming that you are using SOAPpy, You can do .
#!/usr/bin/python
import SOAPpy
url= 'https://linksearch.api.cj.com/wsdl/version2/linkSearchServiceV2.wsdl'
proxy = SOAPpy.WSDL.Proxy(url)
results=proxy.searchLinks({'developerkey': 'dev_key','token':'','websiteId': 'website_id','advertiserIds':'joined'})

Related

Send an array from Python to PHP

I am trying to consume with Python a WSDL created in PHP.
Fragment of the Service:
require_once('lib/nusoap.php');
date_default_timezone_set('America/Mexico_City');
function Sum($numbers){
return array_sum($numbers);
}
...
Client:
from suds.client import Client
def wsarchivo():
url = "http://localhost/PracticeSumArray/server.php?wsdl"
client = Client(url)
res = client.service.Sum([1,2,3])
print(res)
wsarchivo()
But when running it does not work to send the parameter in this way, unlike doing it with a client in PHP that the way to send the parameter would be 'numbers' => array (1, 2, 3) and works correctly .
I could solve my problem, I leave it here in case someone else is useful, the first mistake I made was to declare the input parameter as a whole xsd:int, so what I did was declare it as SOAP-ENC:Array on the server in PHP:
$server->register(
'Suma',
array('numbers' => 'SOAP-ENC:Array'),
array('return' => 'xsd:int'),
$ns
);
Now in the Python client I used the factory.create() method of the suds client to declare a variable with the type SOAP-ENC:Array
from suds.client import Client
def wsarchivo():
client = Client("http://localhost/PracticaSumaArray/server.php?wsdl")
request = client.factory.create('SOAP-ENC:Array')
request.numbers = [1,2,3]
res = client.service.Suma(request)
print(res)
wsarchivo()
When executing:
Output:
6

need help in PHP soap

i try to fetch result from www.tadawul.com.sa with php soap client.
but when i try to load that , get nothing just loading page.
here is my code.
$reference = array(
'companyId' => '*********',
'secureKey' => '*********'
);
$client = new SoapClient('http://www.tadawul.com.sa/Tadawul_WebAPI/services/GetDetailQuote?wsdl');
$response = $client->getDetailQuoteForCompany($reference);
var_dump($response);
I think the problem is in the structure you need to pass a getDetailQuoteForCompanyRequest Object not an array
Why don't you use wsdl2phpgenerator
It'll make you life easier, You need to pass wsdl file and it will generate all the classes that you need
Instead of this
$response = $client->getDetailQuoteForCompany($reference);
Try
$response = $client->__soapCall("getDetailQuoteForCompany", array($reference));

How can I get base64 to display as a base64 string in PHP?

I have been working with an API that uses tokens for authentication. I am using PHP's SoapClient class to login to said API and retrieve the tokens I need to make additional requests..
The problem is that the API should return base64 string tokens, but in PHP, they are not being dealt with as bas64 strings.. I get a string that looks like this:
ç$P%’™‹2E‡ºË>Šo_ÑÒúé±N5Tá#=œã
Instead of a base64 string that looks like this:
ERy/R5ycTG0sbRyH9KeMGpi9kPr6kROyaarFYgsPEOU=
Note: These 2 strings are not actually related, as I could not get php to display the base64 representation of that 1st string. The base64 string I listed as the 2nd string came from a valid soapUI response.
So I have confirmed with soapUI, that I the tokens do in fact come over as base64 strings, but I cannot get PHP to use them as strings for additional requests. I have tried doing base64_decode and base64_encode on the strings, along with a bunch of other encodings/decodings, but none of them have worked so far.
Any ideas as to what is going on here, and how I might be able to use the data the way I need?
Edit: Here is the code I use to get the token data. It's the DAT api if that helps.
$wsdlDat = "http://someurl.com:8000/wsdl/someWSDL.wsdl";
$soapOptions = array( 'loginId' => $userName, 'password' => $userPassword, 'thirdPartyId' => 'KEFKA_TMS', 'trace' => 1 );
$this->datClient = new SoapClient( $wsdlDat , $soapOptions );
$creds = array( 'loginId' => $userName, 'password' => $userPassword, 'thirdPartyId' => 'KEFKA_TMS' );
$loginOptions['loginOperation'] = $creds;
$this->token = $this->datClient->Login($loginOptions);
$this->token = datObjectToArray($this->token); // TURN STD CLASS OBJ TO ARRAY
$token = $this->token['loginResult']['loginSuccessData']['token']['primary'];
$token2 = $this->token['loginResult']['loginSuccessData']['token']['secondary'];
$exp = $this->token['loginResult']['loginSuccessData']['expiration'];

Updating XML with PHP and returning to .NET Web Service dataset with SOAP

I am using PHP5 and Codeigniter to connect to a .NET web service through SOAP requests. I'm having trouble making an update to that dataset. This is my first experience working with Codeigniter (although doesn't factor here much), SOAP, PHP SimpleXML class, and .NET web services in general. For example, this is to update a user profile. I don't have any problems getting responses but I'm unsure how to update this based on the user's edits to the profile.
My string from the dumping request is this (Note: I'm concerned with the 0, which is the start of the dataset. The 1111 is username and the next 1111 is a password)
11111111 0RandyFloydGM1955-11-05T00:00:00-04:00317787129131789770001910 E. Markwood AvenueIndianapolisIN46227falsefalse
This gives me a 400 Bad Request error. It seems obvious that is due to the space between the 0 and the last 1. By doing htmlspecialchars() I see that it looks like it is the xml declaration isn't needed.
<?xml version="1.0"?> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml- msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><dsEmployee xmlns="http://SHSSrv/dsEmployee.xsd"><Employee diffgr:id="Employee1" msdata:rowOrder="0"><EmplId>0</EmplId><FirstName>Randy</FirstName><LastName>Floyd</LastName><MI>G</MI><Sex>M</Sex><DOB>1955-11-05T00:00:00-04:00</DOB><HomePhoneArea>317</HomePhoneArea><HomePhone>7871291</HomePhone><WorkPhoneArea>317</WorkPhoneArea><WorkPhone>8977000</WorkPhone><Address1>1920 E. Markwood Avenue</Address1><Address2/><City>Indianapolis</City><St>IN</St><ZIP>46227</ZIP><ReceiveNewsLetter>false</ReceiveNewsLetter><PagerArea/><PagerNo/><EmailAddress>randy#test.com</EmailAddress><SpanishContact>false</SpanishContact></Employee></dsEmployee></diffgr:diffgram>
Taking the original response and just sending it back as update works like this.
111111110RandyFloydGM1955-11-05T00:00:00-04:00317787129131789770001910 E. Markwood AvenueIndianapolisIN46227falsefalse
And with htmlspecialchars() looks like this (No XML declaration):
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml- msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><dsEmployee xmlns="http://SHSSrv/dsEmployee.xsd"><Employee diffgr:id="Employee1" msdata:rowOrder="0"><EmplId>0</EmplId><FirstName>Randy</FirstName><LastName>Floyd</LastName><MI>G</MI><Sex>M</Sex><DOB>1955-11-05T00:00:00-04:00</DOB><HomePhoneArea>317</HomePhoneArea><HomePhone>7871291</HomePhone><WorkPhoneArea>317</WorkPhoneArea><WorkPhone>8977000</WorkPhone><Address1>1920 E. Markwood Avenue</Address1><Address2/><City>Indianapolis</City><St>IN</St><ZIP>46227</ZIP><ReceiveNewsLetter>false</ReceiveNewsLetter><PagerArea/><PagerNo/><EmailAddress>randy#test.com</EmailAddress><SpanishContact>false</SpanishContact></Employee></dsEmployee></diffgr:diffgram>
Here is the code:
function employee_update_request()
{
ini_set( 'soap.wsdl_cache_ttl' , 0 );
//Get XML from the Employee Profile Request
$response = $this->employee_profile_request();
//Turn the string into an object to manipulate
$dataset = simplexml_load_string($response->any);
//Manipulate some data from the update form
$dataset->dsEmployee->Employee->EmailAddress = "randy#test.com";
$dataset->dsEmployee->Employee->Address1 = "1920 E. Markwood Avenue";
$any = $dataset->saveXML();
//Add back the string to the original response object returned from web service
$response->any = $any;
//Get username and password for the params
$username = $this->session->userdata('username');
$password = $this->session->userdata('password');
$params = array('sUserId' => $username, 'sPassword' => $password, 'dsEmployee' => $response);
//SOAP Options
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=> 0,
'trace'=> 1,
'uri' => "http://www.w3.org/2003/05/soap-envelope"
);
//New soap client with options
$client = new SoapClient('http://localhost/SHSSRV/SHSSrv.asmx?WSDL', $options);
//Request the employee profile fromt the webservice, passing in credentials
$update_request = $client->EmployeeUpdateRequest($params);
$update_response = $update_request->EmployeeUpdateRequestResult;
return $update_response;
}
I really need help, I need to figure out how best to make updates to this data. Am I able to get the declaration stripped out somehow, or should I request that the .NET web service be changed in some way? I don't have access directly to that but I can talk to the developer if there is a better way all together.
Thanks!
I've solved this by doing this. I'd love to know if there is a better way though.
$no_xml_doctype = str_replace('<?xml version="1.0"?>' , '' , $any);
$trimmed = trim($no_xml_doctype);
$response->any = $trimmed;
//Get username and password for the params
$username = rtrim($this->session->userdata('username'));
$password = rtrim($this->session->userdata('password'));
$params = array('sUserId' => $username, 'sPassword' => $password, 'dsEmployee' => $response);

Read long value from webservice using SoapClient

I'm writing a soap consumer in PHP for a ws written in Java (Jax ws). The webservice exports a function listRooms() that returns an array of the complex data type Room which contains an id (64 bit long) and a description (string). Now whenever I consume the webservice using SoapClient, the id is converted to float (as there are no 64 bit integers in PHP) and I want to avoid it. As I will need the room id to consume other web services I would rather avoid this implicit conversion to float, keeping it in a string.
Does anyone know how to solve this problem?
This might help:
The long overflows because ext/soap maps it to an int, and you're on a 32bit arch. You can easily fix that problem by using a custom type mapper to override the internal handling of {http://www.w3.org/2001/XMLSchema }long:
function to_long_xml($longVal) {
return '<long>' . $longVal . '</long>';
}
function from_long_xml($xmlFragmentString) {
return (string)strip_tags($xmlFragmentString);
}
$client = new SoapClient('http://acme.com/products.wsdl', array(
'typemap' => array(
array(
'type_ns' => 'http://www.w3.org/2001/XMLSchema',
'type_name' => 'long',
'to_xml' => 'to_long_xml',
'from_xml' => 'from_long_xml',
),
),
));
Also check to see exactly what you get back from the SOAP call, as per the manual add 'trace' and use getLastRequest:
<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
?>
Other way to do it, is just using the float() function before the data to sent as a long type.
In the example below I'm use a stdclass object to sent as a parameter:
<?php
if ($index == "Your_longtype_Field"){
$a->$index = (float) $value;
} else {
$a->$index = $value;
}
?>

Categories