I am accessing web service which is hosted in IIS from perl script. I have a methos in service which returns an array of string. I am not able to read the response from service. By using Dumper i printed the response returned by service, and there I can see the array values but I am not able to access the array values. How to access thr array values returned form web service method.
Calling of method in perl:
my $method2 = SOAP::Data->name('getCustInfo')->attr({xmlns => 'http://tempuri.org/'});
my #param=(SOAP::Data->name(custId=>$custid));
my $response1= $soap->call($method2=>#param);
print $response1;
print Dumper $response1;
#result11=$response1->result;
print Dumper $response1;
$i=-1;
foreach my $result(#result11)
{
++$i;
print $result[$i];
}
The above code I am using to access the method, and I am trying to print it but it not working its giving: HASH(0x3a84518)$VAR1 = undef; What is the problem.
Thanks,
Avinash
Before knowing the response check whether the call happens.
use strict;
use warnings;
use SOAP::Lite +trace=>"debug"; # it debugs whether the connection is set or not
my ($soap,$proxy,$uri);
eval {
$soap = new SOAP::Lite
proxy=>$proxy,
uri=>$uri;
};
if ( $# ){
print " Service Down\n";
}
For the soap call, it requires the proxy and the uri kindly have those in the eval to check whether they are accessible.
Related
So I was trying to connect our SMS (Student Management System) to a government Service or Site. The process requires an authentication token coming from Vanguard. Successfully, I am able to obtain the token... but due to lack of documentation and sample codes in PHP I am having problem communicating to the said service. I was wondering if is it my code that causes the problem or is it my calls that has conflict interfacing to the webservice: Please see code below:
<?php
require_once 'VanguardClient.php';
$endpoint = 'https://3pt.portal.usi.gov.au/Service/v2/UsiService.svc';
function get_sts($endpoint){
$test = true;
$auskey_path = 'Keystore.xml';
$auskey_password = 'Password1!';
$v = new VanguardClient($test);
$v->loadAuskey($auskey_path, $auskey_password);
try {
return $v->requestToken($endpoint);
} catch (SoapFault $e) {
echo "Error1:";
echo $e;
}
}
//get token from Vanguard
$token = get_sts($endpoint);
//create soap client
try{
$wsdl = 'https://3pt.portal.usi.gov.au/service/V2/UsiService.wsdl';
$client = new SoapClient($wsdl,
array(
'trace' =>1,
//'soap_version' => SOAP_1_2,
'keep_alive' => false,
//'connection_timeout' => 500000,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
} catch (SoapFault $e) {
echo "SoapClient Error:<br />";
var_dump($e);
}
try {
$result=$client->__setSoapHeaders( $token );
} catch (SoapFault $e) {
echo "__setSoapHeaders:";
var_dump($e);
}
$data = array(
'OrgCode' => '970003',
'USI' => 'U6Q8JN6UD9',
'FirstName' => 'Myrna',
'FamilyName' => 'Macknight',
'DateOfBirth' => '1971-04-19'
);
try{
$response=$client->__soapCall('VerifyUSI',$data);
} catch (SoapFault $e) {
echo "__soapCall Error:<br />";
echo $e;
}
var_dump($response);
The result on the browser that I am seeing is this:
SoapFault exception: [HTTP] Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'. in /var/www/html/usitest/example1.php:73 Stack trace: #0 [internal function]: SoapClient->__doRequest('__soapCall('VerifyUSI', Array) #2 {main}NULL
Thanks in advance guys!!!
Your content type is probably caused by the SOAP version.
Try setting the SOAP version to 1.2:
'soap_version' => SOAP_1_2
See SoapClient connection to SoapServer
However, I think there are other issues in your code - particularly with the Vanguard token.
We managed to solve this however it took many classes, templates, external packages and months of work to solve and is not something we can put up online. However there are some things I'd suggest you do to solve it in your situation.
This does not work like a normal SOAP service. Use XML templates for all steps of the various process (Vanguard, USI, components of these sections etc).
Reverse engineer the .Net example code, we had major issues with the Java code.
We made major headway by using a proxy and capturing the content sent and received.
Unless you are using composer to manage your security dependencies you're going to have a bad time, even with composer it was a pain.
There are about 10 sections to do with security that have to be reverse engineered, don't forget to canonicalise the content to get the encryption correct.
Use Guzzle for the requests, it's easier
Most of the stuff in the PHP example is wrong, or at least impossible to follow and debug to fix. At the end we couldn't see a way that it would work.
Expect to spend at least a couple of weeks on it and you need to know a lot about security, hashing and ssl certificates.
Sorry I can't give you a full working solution but knowing these steps above would have definitely helped us and so I hope they'll help you.
There is PS script for verifying webservice and it works:
$SiteURL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP"
$request = [Net.HttpWebRequest]::Create($SiteURL)
try
{
#Get the response from the requst
$response = [Net.HttpWebResponse]$request.GetResponse()
Write-Host "The service is running."
$request.Abort()
}
Catch
{
Write-Warning "The service of site does not run or maybe you don't have the Credential"
}
But how I can specify query parameter, ZIP?
add a $zip parameter to get zip as an input
param($zip)
update your url to include zip when sending request
$siteURL="http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=$zip"
I have followed the instructions of the mailgun, including dots and commas. I installed composer successfully. My domain name is also verified so I wanted to use API for sending emails.
I created a simple application for testing if emails are going or not.
here is the code of sample php application:
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mg = new Mailgun("key-********************************");
$domain = "https://api.mailgun.net/v3/mailgun.************.com/messages";
$mg->sendMessage($domain,
array(
'from' => 'noreply#********.com',
'to' => '********#hotmail.com',
'subject' => 'The mailgun is awesome!',
'text' => 'It is so simple to send a message.'));
echo "done";
?>
I get internal server error 500 when I run this file.
When I change the $domain to "mailgun.*****.com" I get emails but in junk folder
I am confused what is happening here.. no apparent fault..
May be some expert will be able to help me out here..
The $domain has to be the same as entered in your settings.
i.e. the domain is mg.domain.com in your mailgun account,
your $domain is domain.com.
Also your from has to be [anything]#domain.com, to be accepted.
I am running a clojurescript (cljs) browser repl and I want to be able to write some text to a local file.
I tried the following:
(spit "abc.txt" "hello")
but this returns:
#<TypeError: Cannot read property 'call' of undefined>
TypeError: Cannot read property 'call' of undefined
Under a clojure repl this will create file "abc.txt" in the root dir of my project.
I realize that 'spit is a clojure function, but I wonder if there is also some easy way to do this in cljs?
Or is this strictly a JavaScript question and not relevant to clojurescript proper?
From a browser I think you can't (like in JS), because security.
From nodejs check the nodejs doc :)
Now if you mix in a little bit of flash (yuk :|...) there's a JS library for that (that you can use in cljs).
https://github.com/dcneiner/Downloadify
I am posting this as an example solution, and I am not saying this is how you should do it. I did experience a few "gotchas" however, so I
think it's worthwhile to document.
Thank you for your answer. I was just trying to find out if there was some easier way before doing what I knew I would have to do otherwise. I decided to go with a server-side write.
I am using cider, chestnut, and a brepl server interfacing with a chrome client. Since I am not familiar with ring servers, compojure, and embedded jetty servers, I did not know how to add a web service to the brepl server (port 10555). Instead I added one to my local apache server.
Because the request comes in to apache from the the jetty server (as opposed to from a browser), I was getting "cross origin resource sharing" issues, namely message:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
whenever I submitted a request to my service's URL.
I was able to get around this issue by adding the following to my http headers:
-access_control_allow_credentials => 'true',
-access_control_allow_origin => 'http://localhost:10555',
That was about the only gotcha. Beyond that, it's a standard cgi solution (yeah, old school -- I come from a perl background). And yes, I know it would have been best if I could have done it in clojure (or Rails).
My cgi ended up looking something like:
#!/usr/bin/perl
use CGI qw(:standard);
print header(
-type => 'text/html',
-access_control_allow_credentials => 'true',
-access_control_allow_origin => 'http://localhost:10555',
);
my $q = CGI->new();
my $src = $q->param('src');
# write to file
open(my $fh, ">>", "vt-src-out.txt")
or die "cannot open < vt-src-out.txt: $!";
print $fh "$src\n";
I used ajax.core as my client api:
:require [ajax.core :refer [GET POST]]
and called the service like:
(GET "http://localhost/cgi-bin/cljs-write-src.cgi" {:params {:src "(defn foo [])(+ 1 1)"}})
node.js example.
Less hassle than writing a cgi.
New to node.js, so just a starter. Did not convert to cljs.
// to run:
// node write_file.js
// to call from cmd line:
// curl localhost:9090?fn=test.txt\&msg=hello%20world
var http = require('http');
var fs = require('fs');
var url = require('url');
var server = http.createServer(function(req, res) {
var fn = url.parse(req.url, true).query['fn'];
var msg = url.parse(req.url, true).query['msg'];
fs.writeFile(process.env.HOME + "/vtstuff/tmp/" + fn, msg + "\n",
function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
console.log("fn=" + fn);
console.log("msg=" + msg);
process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});
});
res.writeHead(200,{"Content-Type": "text/plain"});
res.end("wrote file\n");
});
server.listen(9090);
I am trying to do a simple soap call to a weather service and I keep getting Invalid ZIP error. Can someone tell me what I am doing wrong below is my code.
Thanks
require_once 'SOAP/Client.php';
$client = new Soap_Client('http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL');
$method = 'GetCityWeatherByZIP';
$params = array('ZIP' => '07108');
$result = $client->call($method, $params);
if (PEAR::isError($result)) {
echo $result->getMessage();
} else {
print_r($result);
}
Use PHP's in-built SOAP client. The one in PEAR was written at a time PHP did not have one itself.
Their service is no SOAP service. The wiki states:
$url = "http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityForecastByZIP";
$url .= "?ZIP=" . $this->ZipCode;
$this->response = simplexml_load_file($url) or die("ERROR");