Loading ...
Sorry, an error occurred while loading the content.

Consuming .NET service

Expand Messages
  • jbpion
    Hello all, I am afraid that I am new to SOAP and hope that my question has not already been answered in the archives (I ve looked at a lot of posts to find the
    Message 1 of 4 , Jun 15, 2002
    • 0 Attachment
      Hello all,

      I am afraid that I am new to SOAP and hope that my question has not
      already been answered in the archives (I've looked at a lot of posts
      to find the answer, but have yet to find a solution.)

      I am trying to write a SOAP:Lite client on Unix that will consume a
      .NET web service.

      I have already had success creating a server and client on the Unix
      box following the examples in the documentation and the Perl.com
      "Getting Started" guide.

      Unfortunately, I am not having the same luck with my connection
      attempts to .NET.

      A colleague created a simple web service that returns a dataset from a
      demo database.

      I extracted the .wsdl file using disco.exe and moved it to the same
      directory as my client script. According to the debug information I
      appear to be connecting.

      The documentation makes the process of returning the result set seem
      quite easy. However, whenever I try to invoke the result method I get
      "Can't call method result on unblessed reference".

      If I look at the value returned directly it appears to be a hash
      reference containing a hash of hashes, the first two keys of which are
      diffgram and schema.

      Below are the perl script, the wsdl file, and the debug output. Any
      help would be most appreciated.

      -Jerome Pion

      P.S. I apologize for the length of my post.

      Client script:
      #! /usr/local/bin/perl
      use SOAP::Lite;
      my $s = SOAP::Lite
      ->service('file:///perl/SOAP/dataservice.wsdl')
      ->on_debug(sub{print @_})
      ->GetAuthors(ca)
      ;
      print $s->result;

      WSDL File:
      <?xml version="1.0" encoding="utf-8"?>
      <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
      xmlns:soap="http
      ://schemas.xmlsoap.org/wsdl/soap/"
      xmlns:xds="http://www.w3.org/2001/XMLSchema"
      xmlns:s0="http://tempuri.org/"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/en
      coding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
      xmlns:mime="htt
      p://schemas.xmlsoap.org/wsdl/mime/"
      targetNamespace="http://tempuri.org/" xmlns=
      "http://schemas.xmlsoap.org/wsdl/">
      <types>
      <xds:schema elementFormDefault="qualified"
      targetNamespace="http://tempuri.o
      rg/">
      <xds:import namespace="http://www.w3.org/2001/XMLSchema" />
      <xds:element name="GetAuthors">
      <xds:complexType>
      <xds:sequence>
      <xds:element minOccurs="0" maxOccurs="1" name="sValue"
      type="xds:str
      ing" />
      </xds:sequence>
      </xds:complexType>
      </xds:element>
      <xds:element name="GetAuthorsResponse">
      <xds:complexType>
      <xds:sequence>
      <xds:element minOccurs="0" maxOccurs="1"
      name="GetAuthorsResult">
      <xds:complexType>
      <xds:sequence>
      <xds:element ref="xds:schema" />
      <xds:any />
      </xds:sequence>
      </xds:complexType>
      </xds:element>
      </xds:sequence>
      </xds:complexType>
      </xds:element>
      <xds:element name="DataSet" nillable="true">
      <xds:complexType>
      <xds:sequence>
      <xds:element ref="xds:schema" />
      <xds:any />
      </xds:sequence>
      </xds:complexType>
      </xds:element>
      </xds:schema>
      </types>
      <message name="GetAuthorsSoapIn">
      <part name="parameters" element="s0:GetAuthors" />
      </message>
      <message name="GetAuthorsSoapOut">
      <part name="parameters" element="s0:GetAuthorsResponse" />
      </message>
      <message name="GetAuthorsHttpGetIn">
      <part name="sValue" type="xds:string" />
      </message>
      <message name="GetAuthorsHttpGetOut">
      <part name="Body" element="s0:DataSet" />
      </message>
      <message name="GetAuthorsHttpPostIn">
      <part name="sValue" type="xds:string" />
      </message>
      <message name="GetAuthorsHttpPostOut">
      <part name="Body" element="s0:DataSet" />
      </message>
      <portType name="DataServiceSoap">
      <operation name="GetAuthors">
      <input message="s0:GetAuthorsSoapIn" />
      <output message="s0:GetAuthorsSoapOut" />
      </operation>
      </portType>
      <portType name="DataServiceHttpGet">
      <operation name="GetAuthors">
      <input message="s0:GetAuthorsHttpGetIn" />
      <output message="s0:GetAuthorsHttpGetOut" />
      </operation>
      </portType>
      <portType name="DataServiceHttpPost">
      <operation name="GetAuthors">
      <input message="s0:GetAuthorsHttpPostIn" />
      <output message="s0:GetAuthorsHttpPostOut" />
      </operation>
      </portType>
      <binding name="DataServiceSoap" type="s0:DataServiceSoap">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
      style="docume
      nt" />
      <operation name="GetAuthors">
      <soap:operation soapAction="http://tempuri.org/GetAuthors"
      style="document
      " />
      <input>
      <soap:body use="literal" />
      </input>
      <output>
      <soap:body use="literal" />
      </output>
      </operation>
      </binding>
      <binding name="DataServiceHttpGet" type="s0:DataServiceHttpGet">
      <http:binding verb="GET" />
      <operation name="GetAuthors">
      <http:operation location="/GetAuthors" />
      <input>
      <http:urlEncoded />
      </input>
      <output>
      <mime:mimeXml part="Body" />
      </output>
      </operation>
      </binding>
      <binding name="DataServiceHttpPost" type="s0:DataServiceHttpPost">
      <http:binding verb="POST" />
      <operation name="GetAuthors">
      <http:operation location="/GetAuthors" />
      <input>
      <mime:content type="application/x-www-form-urlencoded" />
      </input>
      <output>
      <mime:mimeXml part="Body" />
      </output>
      </operation>
      </binding>
      <service name="DataService">
      <port name="DataServiceSoap" binding="s0:DataServiceSoap">
      <soap:address
      location="http://nt2ktest.ads.cpicorp.com/MyService/dataserv
      ice.asmx" />
      </port>
      <port name="DataServiceHttpGet" binding="s0:DataServiceHttpGet">
      <http:address
      location="http://nt2ktest.ads.cpicorp.com/MyService/dataserv
      ice.asmx" />
      </port>
      <port name="DataServiceHttpPost" binding="s0:DataServiceHttpPost">
      <http:address
      location="http://nt2ktest.ads.cpicorp.com/MyService/dataserv
      ice.asmx" />
      </port>
      </service>
      </definitions>

      Debug Output
      POST http://nt2ktest.ads.cpicorp.com/MyService/dataservice.asmx
      Accept: text/xml
      Accept: multipart/*
      Content-Length: 453
      Content-Type: text/xml; charset=utf-8
      SOAPAction: "http://tempuri.org/GetAuthors"

      <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
      xmlns:SOAP-ENC="http:/
      schemas.xmlsoap.org/soap/encoding/"
      SOAP-ENV:encodingStyle="http://schemas.xmls
      ap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope
      " xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:xsd="http://www.w
      .org/1999/XMLSchema"><SOAP-ENV:Body><GetAuthors
      xmlns=""><parameters>ca</parame
      ers></GetAuthors></SOAP-ENV:Body></SOAP-ENV:Envelope>
      HTTP/1.1 200 OK
      Cache-Control: private, max-age=0
      Date: Sun, 16 Jun 2002 06:51:26 GMT
      Server: Microsoft-IIS/5.0
      Content-Length: 1284
      Content-Type: text/xml; charset=utf-8
      Client-Date: Sun, 16 Jun 2002 06:50:49 GMT
      Client-Peer: 131.100.88.211:80

      <?xml version="1.0" encoding="utf-8"?><soap:Envelope
      xmlns:soap="http://schemas.
      xmlsoap.org/soap/envelope/"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
      "
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap
      :Body><GetAuthorsResponse
      xm
      lns="http://tempuri.org/"><GetAuthorsResult><xs:schema id="NewDataSet"
      xmlns=""
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:msdata="urn:schemas-microsoft-
      com:xml-msdata"><xs:element name="NewDataSet"
      msdata:IsDataSet="true"><xs:comple
      xType><xs:choice maxOccurs="unbounded"><xs:element
      name="AuthorsList"><xs:comple
      xType><xs:sequence><xs:element name="au_lname" type="xs:string"
      minOccurs="0" />
      <xs:element name="au_fname" type="xs:string" minOccurs="0"
      /><xs:element name="p
      hone" type="xs:string" minOccurs="0" /><xs:element name="address"
      type="xs:strin
      g" minOccurs="0" /><xs:element name="city" type="xs:string"
      minOccurs="0" /><xs:
      element name="state" type="xs:string" minOccurs="0" /><xs:element
      name="zip" typ
      e="xs:string" minOccurs="0"
      /></xs:sequence></xs:complexType></xs:element></xs:c
      hoice></xs:complexType></xs:element></xs:schema><diffgr:diffgram
      xmlns:msdata="u
      rn:schemas-microsoft-com:xml-msdata"
      xmlns:diffgr="urn:schemas-microsoft-com:xml
      -diffgram-v1"
      /></GetAuthorsResult></GetAuthorsResponse></soap:Body></soap:Envel
      ope>
      Can't call method "result" on unblessed reference at ./test8.pl line
      16.
    • Duncan Cameron
      ... What is ca? Should it be ca ? ... You don t want this. GetAuthors() returns the real result. See the examples in the SOAP::Schema section of the pod.
      Message 2 of 4 , Jun 16, 2002
      • 0 Attachment
        On 2002-06-16 jbpion wrote:
        >Hello all,
        >
        >I am afraid that I am new to SOAP and hope that my question has not
        >already been answered in the archives (I've looked at a lot of posts
        >to find the answer, but have yet to find a solution.)
        >
        >I am trying to write a SOAP:Lite client on Unix that will consume a
        >..NET web service.
        >
        >I have already had success creating a server and client on the Unix
        >box following the examples in the documentation and the Perl.com
        >"Getting Started" guide.
        >
        >Unfortunately, I am not having the same luck with my connection
        >attempts to .NET.
        >
        >A colleague created a simple web service that returns a dataset from a
        >demo database.
        >
        >I extracted the .wsdl file using disco.exe and moved it to the same
        >directory as my client script. According to the debug information I
        >appear to be connecting.
        >
        >The documentation makes the process of returning the result set seem
        >quite easy. However, whenever I try to invoke the result method I get
        >"Can't call method result on unblessed reference".
        >
        >If I look at the value returned directly it appears to be a hash
        >reference containing a hash of hashes, the first two keys of which are
        >diffgram and schema.
        >
        >Below are the perl script, the wsdl file, and the debug output. Any
        >help would be most appreciated.
        >
        >-Jerome Pion
        >
        >P.S. I apologize for the length of my post.
        >
        >Client script:
        >#! /usr/local/bin/perl
        >use SOAP::Lite;
        >my $s = SOAP::Lite
        > ->service('file:///perl/SOAP/dataservice.wsdl')
        > ->on_debug(sub{print @_})
        > ->GetAuthors(ca)
        > ;

        What is ca? Should it be 'ca' ?

        >print $s->result;

        You don't want this. GetAuthors() returns the real result.
        See the examples in the 'SOAP::Schema' section of the pod.
        >
        .. snipped ...

        > <diffgr:diffgram
        > xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
        > xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"/>

        This is where your resultant authors would be, but there aren't any!

        >Can't call method "result" on unblessed reference at ./test8.pl line
        >16.
        Caused by $s->result;


        Regards,
        Duncan Cameron
      • jbm15260
        I m having the same problem, but it seems as though a blessed reference is returned when you use the uri and proxy methods, but not when you use the service
        Message 3 of 4 , Jun 17, 2002
        • 0 Attachment
          I'm having the same problem, but it seems as though a blessed
          reference is returned when you use the uri and proxy methods, but not
          when you use the service method.

          This works:

          my $result = SOAP::Lite
          -> uri("myservice")
          -> proxy("http://localhost:5125")
          -> processFile(SOAP::Data->type(base64 => $file_contents));

          if ($result->fault) {
          print "\n", $result->faultcode, " ", $result->faultstring, "\n\n";
          }
          else {
          my %resulthash = %{$result->result};
          print "\ncode: $resulthash{'code'}\n";
          print "string: $resulthash{'string'}\n\n";
          }

          But removing the uri and proxy calls and replacing them with a service
          call, as:

          -> service('http://localhost:3561/myservice.wsdl')

          Gives me the "Can't call method "fault" on unblessed reference"
          error. I don't understand why $result is a blessed reference in the
          former case but not in the latter. Is this a bug or am I missing
          something?
        • Jerome Pion
          ... Thank you for your help. After Duncan narrowed the problem for me (the service was not returning any data) I was able to come up with a solution. I tried
          Message 4 of 4 , Jun 17, 2002
          • 0 Attachment
            --- jbm15260 <jbm15260@...> wrote:
            > I'm having the same problem, but it seems as though
            > a blessed
            > reference is returned when you use the uri and proxy
            > methods, but not
            > when you use the service method.
            >
            > This works:
            >
            > my $result = SOAP::Lite
            > -> uri("myservice")
            > -> proxy("http://localhost:5125")
            > -> processFile(SOAP::Data->type(base64 =>
            > $file_contents));
            >
            > if ($result->fault) {
            > print "\n", $result->faultcode, " ",
            > $result->faultstring, "\n\n";
            > }
            > else {
            > my %resulthash = %{$result->result};
            > print "\ncode: $resulthash{'code'}\n";
            > print "string: $resulthash{'string'}\n\n";
            > }
            >
            > But removing the uri and proxy calls and replacing
            > them with a service
            > call, as:
            >
            > -> service('http://localhost:3561/myservice.wsdl')
            >
            > Gives me the "Can't call method "fault" on unblessed
            > reference"
            > error. I don't understand why $result is a blessed
            > reference in the
            > former case but not in the latter. Is this a bug or
            > am I missing
            > something?
            >
            >

            Thank you for your help.

            After Duncan narrowed the problem for me (the service
            was not returning any data) I was able to come up with
            a solution.

            I tried sending a post to the group, but it never
            showed up.

            The method, GetAuthors, accepts a US state
            abbreviation and returns a list of author names and
            addresses. The data is returned between <AuthorsList>
            tags.

            The solution I came up with was:
            #! /usr/local/bin/perl
            use SOAP::Lite;

            $debug =1;
            $soap = SOAP::Lite
            ->uri('http://tempuri.org/GetAuthors/')
            ->proxy('http://nt2ktest/MyService/dataservice.asmx')
            ->on_action(sub {join '', @_})
            ;

            $soap ->on_debug(sub{print @_}) if $debug;

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

            my @rc = $soap->call($method =>
            SOAP::Data->name('sValue' =>
            'ca'))->valueof('//AuthorsList');

            foreach $item (@rc){
            foreach $key (keys %$item){
            print $item->{$key},'|';
            }
            print "\n";
            }

            You'll notice that I'm using uri/proxy instead of
            service. If I try using ->service I get a "Transport
            is not specified" error so I am unable to test your
            theory.

            The above works for me, and I can get the information
            I need about the web service by calling the .asmx file
            from my browser. I'm going to continue playing around
            with the the service method, and with the code you
            provided.

            Thanks again,
            -Jerome Pion

            __________________________________________________
            Do You Yahoo!?
            Yahoo! - Official partner of 2002 FIFA World Cup
            http://fifaworldcup.yahoo.com
          Your message has been successfully submitted and would be delivered to recipients shortly.