soap query with php and wsdl to get result - php

I'm having trouble finding a good example of how to do a soap call with a wsdl in php.
I found this example, but it's tied to the google function:
doGoogleSearch
$hits = $soap->doGoogleSearch('your google key',$query,0,10,
true,'',false,'lang_en','','');
I found this example for a wsdl, but I'm not seeing where my query goes:
missingQuery
So basically, this is what I have so far, but there's a lot missing:
$wsdlDB = "htmlString?wsdl";
// xml string for login and query I know works in soapUI with $var
$query = "$query =
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tri="http://blah/dbOurs/">
<soapenv:Header/>
<soapenv:Body>
<tri:sendTransaction>
<loginName>unernm</loginName>
<loginPassword>pw</loginPassword>
...
</soapenv:Body>
</soapenv:Envelope>'
$result = "not sure where this ties in either";
$WSDL = new SOAP_WSDL($wsdlDB);
$soap = $WSDL->getProxy();
$hits = $soap->($query, $result);
//then I will extract $varAnswer from $result with regex probably
This is really unclear. Does anyone have any helpful info on how to submit the query to the DB with the WSDL? I shouldn't have to give the soap call a specific function to do the query with. It's supposed to get that from the wsdl definition.

Why not use the built in SoapClient. It will convert the input to the function into a Soap Message and extract the return message into an object; based on the WSDL.
A simple sample is shown below.
$blzCode = '10010424'; // Code to lookup
$wsdlDB = "http://www.thomas-bayer.com/axis2/services/BLZService?wsdl"; // WSDL URL
$client = new SoapClient($wsdlDB); // Create the client based on the WSDL
$returnValue = $client->GetBank(array('blz' => $blzCode)); // Pass in the Parameters to the call (Based on the WSDL's definition)
$bankDetails = $returnValue->details; // Extract the results
$bankName = $bankDetails->bezeichnung; // Extract some portion of the inner result
echo "Blz Code {$blzCode}'s bank name is {$bankName}" . PHP_EOL; // Do something with the data

Related

Trying to post specific PHP form values to SOAP wsdl with no success

Attemping to post PHP form data from another PHP file to a SOAP wsdl based on if statement of one of the criteria. I cannot get his to work for the life of me. I am new so I know I make many mistakes.
if ( isset( $_GET['submit'] ) ){
$INPUT_STATE=$_GET['INPUT_STATE'];
$SHIP_FROM_STATE = $_GET['SHIP_FROM_STATE'];
$SHIP_FROM_ADDRESS= $_GET['SHIP_FROM_ADDRESS'];
$SHIP_FROM_CITY= $_GET['SHIP_FROM_CITY'];
$SHIP_FROM_ZIP= $_GET['SHIP_FROM_ZIP'];
if ($SHIP_FROM_STATE=='CA');
require_once('C:\xampp\htdocs\addemp\Tax\nusoap.php');
$wsdl = 'http://services.gis.boe.ca.gov/api/taxrates/rates.svc?wsdl';
$server = new SoapClient ($wsdl);
$params= SoapFunction(array(
'StreetAddress'=> $SHIP_FROM_ADDRESS,
'City'=>$SHIP_FROM_CITY,
'ZipCode'=> $SHIP_FROM_ZIP));
$result = $server->call('GetRate', $params);
print_r($result);
}ELSE

How to translate PHP SoapClient request example to RoR?

I'd like to use some web service via its API. In documentation I found an example request written with PHP SoapClient. But I am using RoR and I have no PHP experience. Could someone tell me how should I write the same in RoR, or at least translate it to plain HTTP terminology?
<?php
$soap = new SoapClient(“https://secure.przelewy24.pl/external/wsdl/service.php?wsdl”);
$test = $soap->TestAccess(“9999”, “anuniquekeyretrievedfromprzelewy24”);
if ($test)
echo ‘Access granted’;
else
echo ‘Access denied’;
?>
Edit: particularly I'd like to know what should I do with TestAccess method, because there's no methods in plain HTTP. Should I join this name with URL?
To make your life easier, check out a gem that allows you to simplify SOAP access, like savon.
Then the code could be translated as
# create a client for the service
client = Savon.client(wsdl: 'https://secure.przelewy24.pl/external/wsdl/service.php?wsdl')
This will automatically parse the possible methods to client that are offered in the SOAP API (defined in the WSDL). To list the possible operations, type
client.operations
In your case this will list
[:test_access, :trn_refund, :trn_by_session_id, :trn_full_by_session_id, :trn_list_by_date, :trn_list_by_batch, :trn_full_by_batch, :payment_methods, :currency_exchange, :refund_by_id, :trn_register, :trn_internal_register, :check_nip, :company_register, :company_update, :batch_list, :trn_dispatch, :charge_back, :trn_check_funds, :check_merchant_funds, :transfer_merchant_funds, :verify_transaction, :register_transaction, :deny_transaction, :batch_details]
Then to call the method, do the following
response = client.call(:test_access, message: { test_access_in: 9999 })
response = client.call(:test_access, message: {
test_access_in: 9999 }
test_access_out: "anuniquekeyretrievedfromprzelewy24"
)
response.body
=> {:test_access_response=>{:return=>false}}
this gets a result, but I have no idea what it means.
I've included an entire controller method that we use in production as an example but essentially you want to pass in your xml/wsdl request as the body of the HTTP request and then parse the response as xml, or what we used below which is rexml for easier traversing of the returned doc.
def get_chrome_styles
require 'net/http'
require 'net/https'
require 'rexml/document'
require 'rexml/formatters/pretty'
xml = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:description7b.services.chrome.com">
<soapenv:Header/>
<soapenv:Body>
<urn:StylesRequest modelId="' + params[:model_id] + '">
<urn:accountInfo number="[redacted]" secret="[redacted]" country="US" language="en" behalfOf="trace"/>
<!--Optional:-->
</urn:StylesRequest>
</soapenv:Body>
</soapenv:Envelope>'
base_url = 'http://services.chromedata.com/Description/7b?wsdl'
uri = URI.parse( base_url )
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new("/Description/7b?wsdl")
request.add_field('Content-Type', 'text/xml; charset=utf-8')
request.body = xml
response = http.request( request )
doc = REXML::Document.new(response.body)
options = []
doc.get_elements('//style').each do |division|
puts division
options << { :id => division.attributes['id'], :val => division.text }
end
respond_to do |format|
format.json { render :json => options.to_json }
end
end

Django 1.8 (on Python 3) - Make a SOAP request with pysimplesoap

Since one week I'm trying to retrieve some datas from a Dolibarr application including Dolibarr's webservices.
In few words, I'm trying to make a soap request to retrieve user's informations.
At first, I tried to instantiate SoapClient with 'wsdl' and 'trace' parameters, in vain.. SoapClient's object was never been create !
Secondly, I made a made a classical SoapClient's object without 'wsdl', however I used : 'location', 'action', 'namespace', 'soap_ns', 'trace'; It was a success (I think) but It did't work when I called Client's call method.. My dolibarrkey did't match my key on the webservice, but their keys are the same (copy & paste).
For more explanations take a look to dolibarr api (to retrieve datas) with the xlm dataformat.
Link to getUser web service (click on getUser to show parameters):
http://barrdoli.yhapps.com/webservices/server_user.php
Link to xml dataformat (for the SOAP request maybe):
http://barrdoli.yhapps.com/webservices/server_user.php?wsdl
from pysimplesoap.client import SoapClient, SoapFault
import sys
def listThirdParties():
# create a simple consumer
try:
# client = SoapClient(
# "[MyAppDomain]/webservices/server_user.php")
# print(client)
# client = SoapClient(wsdl="[MyAppDomain]/webservices/server_user.php?wsdl", trace=True)
client = SoapClient(
location = "[myAppDomain]/webservices/server_user.php",
action = '[myAppDomain]/webservices/server_user.php?wsdl', # SOAPAction
namespace = "[myAppDomain]/webservices/server_user.php",
soap_ns='soap',
trace = True,
)
print("connected bitch")
except:
print("error connect")
message = dict()
message['use'] = "encoded"
message["namespace"] = "http://www.dolibarr.org/ns/"
message["encodingStyle"] = "http://schemas.xmlsoap.org/soap/encoding/"
message["message"] = "getUserRequest"
parts = dict()
auth = dict()
auth['dolibarrkey'] = '********************************'
auth['sourceapplication'] = 'WebServicesDolibarrUser'
auth['login'] = '********'
auth['password'] = '********'
auth['entity'] = ''
parts["authentication"] = auth
parts["id"] = 1
parts["ref"] = "ref"
parts["ref_ext"] = "ref_ext"
message["parts"] = parts
# call the remote method
response = client.call(method='getUser', kwargs=message)
# extract and convert the returned value
# result = response.getUser
# return int(result)
print(response)
pass
I've "BAD_VALUE_FOR_SECURITY_KEY" into a xlm response, I think it's my request which made with a bad xml dataformat..
shell response :
-------- RESPONSE -------
b'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.dolibarr.org/ns/"><SOAP-ENV:Body><ns1:getUserResponse xmlns:ns1="http://barrdoli.yhapps.com/webservices/server_user.php"><result xsi:type="tns:result"><result_code xsi:type="xsd:string">BAD_VALUE_FOR_SECURITY_KEY</result_code><result_label xsi:type="xsd:string">Value provided into dolibarrkey entry field does not match security key defined in Webservice module setup</result_label></result><user xsi:nil="true" xsi:type="tns:user"/></ns1:getUserResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>'
I really want to know how should I do to make a working soap request with a clean xlm dataformat.
Thanks
Did you try to setup WebService Security (WSSE) with client object? Following examples are taken from https://code.google.com/p/pysimplesoap/wiki/SoapClient
client['wsse:Security'] = {
'wsse:UsernameToken': {
'wsse:Username': 'testwservice',
'wsse:Password': 'testwservicepsw',
}
}
or try to Setup AuthHeaderElement authentication header
client['AuthHeaderElement'] = {'username': 'mariano', 'password': 'clave'}

getting data from SOAP request in php

I have a php web site.Here i need to implement flight searching functionality and booking features.i have used paid API from arzoo,but i can't get the response also i am new to SOAP concepts.here is my code
$input_xml = '<AvailRequest>
<Trip>ONE</Trip>
<Origin>BOM</Origin>
<Destination>JFK</Destination>
<DepartDate>2013-09-15</DepartDate>
<ReturnDate>2013-09-16</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<PreferredClass>E</PreferredClass>
<Eticket>true</Eticket>
<Clientid>xxx</Clientid>
<Clientpassword>xxxx</Clientpassword>
<Clienttype>xxx</Clienttype>
<PreferredAirline>AI</PreferredAirline>
</AvailRequest>';
$client = new SoapClient('http://59.162.33.102/ArzooWS/services/DOMFlightAvailability?wsdl');
$result = $client->__call('getAvailability',array($input_xml));
the output of $result is invalid xml format.Please help me to solve this problem

building a php object equal to xml tag

i am developing an app in php it pulls data from Reuters API i am trying to add the request parameters before making SOAP call , i have the xml which must be generated from my request it must look like this :
<HeadlineMLRequest>
<Filter>
<MetaDataConstraint class="companies" xmlns="http://schemas.reuters.com/ns/2006/04/14/rmds/webservices/news/filter">
<Value>MSFT.O</Value>
</MetaDataConstraint>
</Filter>
</HeadlineMLRequest>
when i build my request parameter object i tried this
protected function getRequest() {
$retval->HeadlineMLRequest->MaxCount = 10;
$retval->HeadlineMLRequest->Filter->MetaDataConstraint->class = "companies";
$retval->HeadlineMLRequest->Filter->MetaDataConstraint->Value = "MSFT.O";
return $retval;
}
but when i echo last xml request i find it like this
<ns1:headlinemlrequest>
<ns1:maxcount>
10
</ns1:maxcount>
<ns1:filter>
<ns2:metadataconstraint class="companies">
<ns2:value>
</ns2:value>
</ns2:metadataconstraint>
</ns1:filter>
if you notice Value is empty although i set it with "MSFT.O" , any help please?
Complex requests with php soap are not well documented and most examples show only basic techniques.
Try the following:
$metaData = '<MetaDataConstraint class="companies" xmlns="http://schemas.reuters.com/ns/2006/04/14/rmds/webservices/news/filter">
<Value>MSFT.O</Value>
</MetaDataConstraint>';
$xmlvar = new SoapVar($metaData, XSD_ANYXML);
$retval->HeadlineMLRequest->Filter->MetaDataConstraint = $xmlVar;

Categories