Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Calling .NET based service using SOAP::Lite for Perl

by Khurrum (Novice)
on Nov 06, 2007 at 02:02 UTC ( #649135=perlquestion: print w/replies, xml ) Need Help??
Khurrum has asked for the wisdom of the Perl Monks concerning the following question:

Hi i have setup a local WCF service with the following specs:

Web Service:
OperationContract: [OperationContract] string SampleTest(Tester test)
DataContract: [DataContract(Name = "Tester")]public class Tester
DataMember: [DataMember(IsRequired = true)]public string Name, [DataMember(IsRequired = true)]public int Age

Now with my Perl script i have been able to successfully call a function with just a simple string parameter but i cant figure out how to call a function which has an object as its argument.

The method i am trying to access is trivial:
public string SampleTest(Tester test)
{
if (test == null)
{
return String.Format("NULL test");
}
}

When i use the following script i always get the above string printed meaning that the argument isnt passed correctly. Here is a relevant portion of the script:

my $method = SOAP::Data->name('SampleTest')
->attr({xmlns => 'http://tempuri.org/'});

my $query =
SOAP::Data
->name(Tester =>
\SOAP::Data->value(
SOAP::Data->name(Name => 'Nathan'),
SOAP::Data->name(Age => 22)
));

print $soap->call($method => $query)->result;

I dont think i am contructing the correct SOAP request. I am not sure how to check my WCF service on what request does it expect. I can access the WSDL file generated by my WCF service but it doesnt tell anything on the format of the SOAP request and response.

Can someone please help me out. Thanks in advance.

Replies are listed 'Best First'.
Re: Calling .NET based service using SOAP::Lite for Perl
by erroneousBollock (Curate) on Nov 06, 2007 at 03:09 UTC
    Don't bother hand-constructing complex types using SOAP::Data.

    Instead use SOAP::WSDL (a subclass of SOAP::Lite) to talk to the web-service. It reads the service's WSDL and constructs a proxy object whose methods are able to marshal pure-perl datastructures to and from the web-service.

    It's otherwise like SOAP::Lite so you can skip straight to the 'USAGE' section of the documentation.

    As with SOAP::Lite (and not mentioned in SOAP::WSDL's docs) you can use $proxy->method(...) instead of $proxy->call('method'...)

    Updated:

    I don't know the specifics of your complexTypes, but you can use something like the following code. Also you likely don't need to specify namespaces as that should be dealt with by SOAP::WSDL.

    use SOAP::WSDL; use Data::Dumper; use strict; my $soap = SOAP::WSDL->new(); $soap->wsdl('http://server/path/to.wsdl'); $soap->on_action(sub { return $_[0].$_[1]; }); # I find this he +lps with .NET services. $soap->proxy('http://server/path/to/service.asmx'); # For speed: not + necessary as SOAP::WSDL can find it in the WSDL. $soap->wsdlinit(caching => 1); my $som = $soap->SampleTest({ Name => 'Nathan', Age => 22}); if ($som->fault) { print "SampleTest Error: ".$som->faultstring."\n"; } else { print Dumper($som->paramsall); }
    Note that the arguments to the method are determined positionally, and that you needn't construct a real Tester object (although if the Tester object you pass is a blessed hash, it doesn't hurt).

    Also, please remember to use <code>...</code> tags when you post code so that it's easier for your fellow monks to read your post.

    -David

      Which version of SOAP::WSDL are you running. I just downloaded 2.00_23 from CPAN but having troubles installing it. I remember i tried it before but no luck. I use the following commands:

      perl Makefile.pl
      make
      make test
      make intall

      During make test some of the test cases are skipped and it complains about the client. Then when i use the Perl script it complains that it cant find the Perl Module WSDL.pm so i manually copied and pasted the perl module in the lib folder for Perl. That seems to solve that problem and then it starts complaining about not finding the perl module Client.pm now i suppose this is same reason "make test" didnt completely pass. Can i install the package somehow other so i dont have to manually find modules and place them in folders? Could you guide me on what i should do?

      Really appreciate your help.
        Which version of SOAP::WSDL are you running.
        My current codebase uses SOAP::WSDL 1.25. That's the version that will install if you issue install SOAP::WSDL from CPAN.

        I've not really used version 2. I'm sure Martin will move the CPAN linkage to version 2 when he feels it's ready.

        During make test some of the test cases are skipped and it complains about the client. Then when i use the Perl script it complains that it cant find the Perl Module WSDL.pm
        You should probably file a bug against v2 here.

        i manually copied and pasted the perl module in the lib folder for Perl. That seems to solve that problem and then it starts complaining about not finding the perl module Client.pm
        That's not a good idea. Sounds like Makefile.PL is broken.

        Can i install the package somehow other so i dont have to manually find modules and place them in folders?
        No one is recommending you do those things.

        Could you guide me on what i should do?
        Use the v1 series.

        -David

        dup, please reap.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://649135]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2018-09-21 12:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (186 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!