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

Re: [soaplite] Re: Calling a web service - please help

Expand Messages
  • Duncan Cameron
    ... I ve been using SOAP::Lite clients to .Net services at work but won t be there until Monday ): From memory I use something like this (untested): $ns =
    Message 1 of 10 , Jun 28, 2002
    • 0 Attachment
      On 2002-06-28 soapnewby wrote:
      >Now I get "Soap call failed: 405 Method not allowed. "
      >
      >Does anyone have an example code snippet of a client calling a web
      >service with .asmx extension?
      >
      >Thanks a lot!
      >Lana
      >
      >
      >
      >--- In soaplite@y..., rjray@b... wrote:
      >> >>>>> "sergei" == sergei lana <soapnewby>
      >> >>>>> wrote the following on Thu, 27 Jun 2002 20:41:04 -0000
      >>
      >> sergei> I don't get any error messages but the thing just doesn't
      >work. :( I
      >> sergei> tested the web service itself and it works OK.
      >>
      >> My guess is that like most .NET services, this one is very picky
      >about the
      >> naming and the namespaces of the arguments you pass to it. Consider
      >looking at
      >> the API documentation, then giving the parameters explicit names
      >and such by
      >> using SOAP::Data calls, rather than passing straight Perl data.
      >>
      >> And don't feel bad-- we all run into this. Perl is very liberal and
      >> accomodating in what it will accept as input, it's easy to forget
      >that most
      >> other languages aren't.
      >>
      >> Randy
      >> --
      >> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
      >"""""""""""
      >> Randy J. Ray
      >rjray@b...
      >> Campbell, CA
      >rjray@s...
      >> <A HREF="http://www.svsm.org">Silicon Valley Scale Modelers</A>
      >

      I've been using SOAP::Lite clients to .Net services at work but won't
      be there until Monday ):

      From memory I use something like this (untested):

      $ns = 'your.services.namespace';
      $soap = SOAP::Lite
      ->uri($ns)
      ->proxy('http://somewhere/xxx.asmx')
      ->on_action(sub {join('/', @_)});

      my $method = SOAP::Data->attr({xmlns => $ns}, 'MyMethod');

      my $r = $soap->call($method,
      SOAP::Data->name(p1 => 23)->type('int'),
      SOAP::Data->name(p2 => 'abcd')->type('string')
      };

      I found that it was essential to have the correct namespace and
      types.

      Regards,
      Duncan Cameron
    • soapnewby
      ... doesn t ... Consider ... and ... forget ... ... won t ... =========================== I plugged this code in but the Web Service still didn t work.
      Message 2 of 10 , Jun 29, 2002
      • 0 Attachment
        --- In soaplite@y..., Duncan Cameron <dcameron@b...> wrote:
        > On 2002-06-28 soapnewby wrote:
        > >Now I get "Soap call failed: 405 Method not allowed. "
        > >
        > >Does anyone have an example code snippet of a client calling a web
        > >service with .asmx extension?
        > >
        > >Thanks a lot!
        > >Lana
        > >
        > >
        > >
        > >--- In soaplite@y..., rjray@b... wrote:
        > >> >>>>> "sergei" == sergei lana <soapnewby>
        > >> >>>>> wrote the following on Thu, 27 Jun 2002 20:41:04 -0000
        > >>
        > >> sergei> I don't get any error messages but the thing just
        doesn't
        > >work. :( I
        > >> sergei> tested the web service itself and it works OK.
        > >>
        > >> My guess is that like most .NET services, this one is very picky
        > >about the
        > >> naming and the namespaces of the arguments you pass to it.
        Consider
        > >looking at
        > >> the API documentation, then giving the parameters explicit names
        > >and such by
        > >> using SOAP::Data calls, rather than passing straight Perl data.
        > >>
        > >> And don't feel bad-- we all run into this. Perl is very liberal
        and
        > >> accomodating in what it will accept as input, it's easy to
        forget
        > >that most
        > >> other languages aren't.
        > >>
        > >> Randy
        > >> --
        >
        >> """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
        "
        > >"""""""""""
        > >> Randy J. Ray
        > >rjray@b...
        > >> Campbell, CA
        > >rjray@s...
        > >> <A HREF="http://www.svsm.org">Silicon Valley Scale Modelers</A>
        > >
        >
        > I've been using SOAP::Lite clients to .Net services at work but
        won't
        > be there until Monday ):
        >
        > From memory I use something like this (untested):
        >
        > $ns = 'your.services.namespace';
        > $soap = SOAP::Lite
        > ->uri($ns)
        > ->proxy('http://somewhere/xxx.asmx')
        > ->on_action(sub {join('/', @_)});
        >
        > my $method = SOAP::Data->attr({xmlns => $ns}, 'MyMethod');
        >
        > my $r = $soap->call($method,
        > SOAP::Data->name(p1 => 23)->type('int'),
        > SOAP::Data->name(p2 => 'abcd')->type('string')
        > };
        >
        > I found that it was essential to have the correct namespace and
        > types.
        >
        > Regards,
        > Duncan Cameron

        ===========================

        I plugged this code in but the Web Service still didn't work.

        Duncan, could you possibly send the actual code when you get back to
        work on Mon.? I'd really appreciate it!

        Could it be that I am missing some Perl Modules for Soap::Lite to
        work? We did download Soap::Lite and XML::Parse from CPAN...

        Is it possible to check somehow that everything Soap::Lite needs is
        there?

        Where else do I look to get this thing to work?

        The client on a .aspx page works just fine but the Perl one doesn't.

        Any ideas, guys???
      • Duncan Cameron
        ... .. snipped ... ... First, use the web interface to your service to show you what the XML needs to look like. In my case I could then figure out how I
        Message 3 of 10 , Jun 29, 2002
        • 0 Attachment
          On 2002-06-29 soapnewby wrote:
          >--- In soaplite@y..., Duncan Cameron <dcameron@b...> wrote:
          .. snipped ...

          >I plugged this code in but the Web Service still didn't work.
          >
          >Duncan, could you possibly send the actual code when you get back to
          >work on Mon.? I'd really appreciate it!
          >
          >Could it be that I am missing some Perl Modules for Soap::Lite to
          >work? We did download Soap::Lite and XML::Parse from CPAN...
          >
          >Is it possible to check somehow that everything Soap::Lite needs is
          >there?
          >
          >Where else do I look to get this thing to work?
          >
          >The client on a .aspx page works just fine but the Perl one doesn't.
          >
          >Any ideas, guys???

          First, use the web interface to your service to show you what the
          XML needs to look like. In my case I could then figure out how
          I should use namespaces and types.

          Second, turn on tracing with SOAP::Lite to show you the generated
          SOAP message:

          use SOAP::Lite +trace => 'debug';

          This should show you where the mismatch is.

          _Then_, if you can't figure it out,please post a sample of your
          code and what the web service is expecting. In fact, always post a
          sample of code, don't just say it doesn't work.

          Regards,
          Duncan Cameron
        • soapnewby
          Duncan, When using trace, I am getting a Soap error related to SoapAction. Do you think you could possibly look at the code below in case you see something
          Message 4 of 10 , Jun 30, 2002
          • 0 Attachment
            Duncan,

            When using trace, I am getting a Soap error related to SoapAction.
            Do you think you could possibly look at the code below in case you
            see something wrong with it? I don't understand why it doesn't like
            this SoapAction... I double-checked and namespace and types look
            OK ... Please help if you can. Thanks SO MUCH!!!
            Lana


            Here is my Perl code:
            =====================================
            my $soap = SOAP::Lite
            ->uri('http://net.trustnet.com/ScorecardService3')
            ->proxy
            ('http://net.trustnet.com/ScorecardService3/ScorecardGenerator.asmx')
            ->on_action(sub {join('/', @_)});

            my $method = SOAP::Data->attr({xmlns
            => 'http://net.trustnet.com/ScorecardService3'}, 'AddItem');

            my $r = $soap->call($method,
            SOAP::Data->name('vchScript' => 'xx')->type('string'),
            SOAP::Data->name('dtLastRan' => '06/30/2002')->type('string'),
            SOAP::Data->name('chSuccessFail' => 's')->type('string'),
            SOAP::Data->name('vchAttempted' => 'a')->type('string'),
            SOAP::Data->name('vchFailed' => 'a')->type('string'),
            SOAP::Data->name('vchErrorMsg' => 'a')->type('string'),
            SOAP::Data->name('iCategory' => 3)->type('int'));

            ========================================

            Here is what the trace error message says:
            ========================================

            SOAP::Transport::HTTP::Client::send_receive: POST
            http://net.trustnet.com/Scorec
            ardService3/ScorecardGenerator.asmx
            Content-Length: 812
            Content-Type: text/xml
            SOAPAction: http://net.trustnet.com/ScorecardService3/

            <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-
            ENC="http://
            schemas.xmlsoap.org/soap/encoding/" SOAP-
            ENV:encodingStyle="http://schemas.xmlso
            ap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-
            instance" xml
            ns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:xsd="http://www.w3
            .org/1999/XMLSchema"><SOAP-ENV:Body><c-gensym5
            xmlns="http://net.trustnet.com/Sc
            orecardService3"><vchScript
            xsi:type="xsd:string">xx</vchScript><dtLastRan xsi:t
            ype="xsd:string">06/30/2002</dtLastRan><chSuccessFail
            xsi:type="xsd:string">s</c
            hSuccessFail><vchAttempted
            xsi:type="xsd:string">a</vchAttempted><vchFailed xsi:
            type="xsd:string">a</vchFailed><vchErrorMsg
            xsi:type="xsd:string">a</vchErrorMsg
            ><iCategory xsi:type="xsd:int">3</iCategory></c-gensym5></SOAP-
            ENV:Body></SOAP-E
            NV:Envelope>
            SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 (Internal
            Server Error
            ) Internal Server Error.
            Cache-Control: private
            Date: Sun, 30 Jun 2002 19:40:27 GMT
            Server: Microsoft-IIS/5.0
            Content-Length: 682
            Content-Type: text/xml; charset=utf-8
            Client-Date: Sun, 30 Jun 2002 19:41:29 GMT
            Client-Peer: 172.31.129.175:80

            <?xml version="1.0" encoding="utf-8"?>
            <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
            <soap:Fault>
            <faultcode>soap:Client</faultcode>
            <faultstring>System.Web.Services.Protocols.SoapException:
            Server did not recognize the value of HTTP Header SOAPAction:
            http://net.trustnet.com/ScorecardService3/.
            at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
            at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type
            type, Http
            Context context, HttpRequest request, HttpResponse response,
            Boolean& abortP
            rocessing)</faultstring>
            <detail />
            </soap:Fault>
            </soap:Body>
            </soap:Envelope>

            ========================================

            So it doesn't like something about SOAPAction. Here is my
            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:s="http://www.w3.org/2001/XMLSchema"
            xmlns:s0="http://net.trustnet.com/ScorecardService3/"
            xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
            xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
            xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
            targetNamespace="http://net.trustnet.com/ScorecardService3/"
            xmlns="http://schemas.xmlsoap.org/wsdl/">
            - <types>
            - <s:schema elementFormDefault="qualified"
            targetNamespace="http://net.trustnet.com/ScorecardService3/">
            - <s:element name="AddItem">
            - <s:complexType>
            - <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="vchScript"
            type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="dtLastRan"
            type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="chSuccessFail"
            type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="vchAttempted"
            type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="vchFailed"
            type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="vchErrorMsg"
            type="s:string" />
            <s:element minOccurs="1" maxOccurs="1" name="iCategory"
            type="s:int" />
            </s:sequence>
            </s:complexType>
            </s:element>
            - <s:element name="AddItemResponse">
            <s:complexType />
            </s:element>
            </s:schema>
            </types>
            - <message name="AddItemSoapIn">
            <part name="parameters" element="s0:AddItem" />
            </message>
            - <message name="AddItemSoapOut">
            <part name="parameters" element="s0:AddItemResponse" />
            </message>
            - <message name="AddItemHttpGetIn">
            <part name="vchScript" type="s:string" />
            <part name="dtLastRan" type="s:string" />
            <part name="chSuccessFail" type="s:string" />
            <part name="vchAttempted" type="s:string" />
            <part name="vchFailed" type="s:string" />
            <part name="vchErrorMsg" type="s:string" />
            <part name="iCategory" type="s:string" />
            </message>
            <message name="AddItemHttpGetOut" />
            - <message name="AddItemHttpPostIn">
            <part name="vchScript" type="s:string" />
            <part name="dtLastRan" type="s:string" />
            <part name="chSuccessFail" type="s:string" />
            <part name="vchAttempted" type="s:string" />
            <part name="vchFailed" type="s:string" />
            <part name="vchErrorMsg" type="s:string" />
            <part name="iCategory" type="s:string" />
            </message>
            <message name="AddItemHttpPostOut" />
            - <portType name="ScorecardGeneratorSoap">
            - <operation name="AddItem">
            <input message="s0:AddItemSoapIn" />
            <output message="s0:AddItemSoapOut" />
            </operation>
            </portType>
            - <portType name="ScorecardGeneratorHttpGet">
            - <operation name="AddItem">
            <input message="s0:AddItemHttpGetIn" />
            <output message="s0:AddItemHttpGetOut" />
            </operation>
            </portType>
            - <portType name="ScorecardGeneratorHttpPost">
            - <operation name="AddItem">
            <input message="s0:AddItemHttpPostIn" />
            <output message="s0:AddItemHttpPostOut" />
            </operation>
            </portType>
            - <binding name="ScorecardGeneratorSoap"
            type="s0:ScorecardGeneratorSoap">
            <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
            style="document" />
            - <operation name="AddItem">
            <soap:operation
            soapAction="http://net.trustnet.com/ScorecardService3/AddItem"
            style="document" />
            - <input>
            <soap:body use="literal" />
            </input>
            - <output>
            <soap:body use="literal" />
            </output>
            </operation>
            </binding>
            - <binding name="ScorecardGeneratorHttpGet"
            type="s0:ScorecardGeneratorHttpGet">
            <http:binding verb="GET" />
            - <operation name="AddItem">
            <http:operation location="/AddItem" />
            - <input>
            <http:urlEncoded />
            </input>
            <output />
            </operation>
            </binding>
            - <binding name="ScorecardGeneratorHttpPost"
            type="s0:ScorecardGeneratorHttpPost">
            <http:binding verb="POST" />
            - <operation name="AddItem">
            <http:operation location="/AddItem" />
            - <input>
            <mime:content type="application/x-www-form-urlencoded" />
            </input>
            <output />
            </operation>
            </binding>
            - <service name="ScorecardGenerator">
            - <port name="ScorecardGeneratorSoap"
            binding="s0:ScorecardGeneratorSoap">
            <soap:address
            location="http://net.trustnet.com/ScorecardService3/ScorecardGenerator
            .asmx" />
            </port>
            - <port name="ScorecardGeneratorHttpGet"
            binding="s0:ScorecardGeneratorHttpGet">
            <http:address
            location="http://net.trustnet.com/ScorecardService3/ScorecardGenerator
            .asmx" />
            </port>
            - <port name="ScorecardGeneratorHttpPost"
            binding="s0:ScorecardGeneratorHttpPost">
            <http:address
            location="http://net.trustnet.com/ScorecardService3/ScorecardGenerator
            .asmx" />
            </port>
            </service>
            </definitions>
            =========================================================
          • rjray@blackperl.com
            It looks like your choice to create the SOAPAction header with the following callback: on_action(sub {join( / , @_)}) is producing a value that the server
            Message 5 of 10 , Jun 30, 2002
            • 0 Attachment
              It looks like your choice to create the SOAPAction header with the following
              callback:

              on_action(sub {join('/', @_)})

              is producing a value that the server doesn't like.

              Setting SOAPAction *should* be a lot simpler than most non-Perl servers make
              it out to be. Most of the behavior I've seen is totally arbitrary-- there are
              few rules regarding SOAPAction in the SOAP spec itself. There's almost as much
              written in the WSDL spec as there is in the core SOAP spec.

              Try not using that callback (let the default behavior have a go at it).
              Otherwise, if this is based on a WSDL spec, look to see what the server is
              expecting as a SOAPAction for the given operation.

              Randy
              --
              """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
              Randy J. Ray rjray@...
              Campbell, CA rjray@...
              <A HREF="http://www.svsm.org">Silicon Valley Scale Modelers</A>
            • soapnewby
              ... The .wsdl file says When I try this simpler version of
              Message 6 of 10 , Jul 1, 2002
              • 0 Attachment
                --- In soaplite@y..., rjray@b... wrote:
                >... look to see what the server is
                > expecting as a SOAPAction for the given operation.

                The .wsdl file says
                <soap:operation
                soapAction="http://net.trustnet.com/ScorecardService3/AddItem"
                style="document" />

                When I try this simpler version of the code:

                SOAP::Lite
                -> uri('http://net.trustnet.com/ScorecardService3/')
                -> proxy
                ('http://net.trustnet.com/ScorecardService3/ScorecardGenerator.asmx')
                -> AddItem (SOAP::Data->name('vchScript' => 'xxx')->type
                ('string'),
                SOAP::Data->name('dtLastRan' => '06/26/2002')->type('string'),
                SOAP::Data->name('chSuccessFail' => 's')->type('string'),
                SOAP::Data->name('vchAttempted' => '2')->type('string'),
                SOAP::Data->name('vchFailed' => '1')->type('string'),
                SOAP::Data->name('vchErrorMsg' => 'ppp')->type('string'),
                SOAP::Data->name('iCategory' => 1)->type('int'));

                The trace error message says:
                <faultstring>System.Web.Services.Protocols.SoapException: Server did
                not recognize the value of HTTP Header SOAPAction:
                http://net.trustnet.com/ScorecardService3/#AddItem.

                ==========

                Why does it append a "#"??
              • Duncan Cameron
                ... That is what SOAP::Lite does by default. You need the on_action() method to override that default. As I explained previously - on_action(sub { join( / ,
                Message 7 of 10 , Jul 1, 2002
                • 0 Attachment
                  On 2002-07-01 soapnewby wrote:
                  >--- In soaplite@y..., rjray@b... wrote:
                  >>... look to see what the server is
                  >> expecting as a SOAPAction for the given operation.
                  >
                  >The .wsdl file says
                  ><soap:operation
                  >soapAction="http://net.trustnet.com/ScorecardService3/AddItem"
                  >style="document" />
                  >
                  >When I try this simpler version of the code:
                  >
                  >SOAP::Lite
                  > -> uri('http://net.trustnet.com/ScorecardService3/')
                  > -> proxy
                  >('http://net.trustnet.com/ScorecardService3/ScorecardGenerator.asmx')
                  > -> AddItem (SOAP::Data->name('vchScript' => 'xxx')->type
                  >('string'),
                  > SOAP::Data->name('dtLastRan' => '06/26/2002')->type('string'),
                  > SOAP::Data->name('chSuccessFail' => 's')->type('string'),
                  > SOAP::Data->name('vchAttempted' => '2')->type('string'),
                  > SOAP::Data->name('vchFailed' => '1')->type('string'),
                  > SOAP::Data->name('vchErrorMsg' => 'ppp')->type('string'),
                  > SOAP::Data->name('iCategory' => 1)->type('int'));
                  >
                  >The trace error message says:
                  ><faultstring>System.Web.Services.Protocols.SoapException: Server did
                  >not recognize the value of HTTP Header SOAPAction:
                  >http://net.trustnet.com/ScorecardService3/#AddItem.
                  >
                  >==========
                  >
                  >Why does it append a "#"??
                  >
                  That is what SOAP::Lite does by default. You need the on_action()
                  method to override that default. As I explained previously

                  ->on_action(sub { join('/', @_)})

                  does the job. All it is doing is joining your uri with your method.
                  In your example above, you already have a trailing '/' on your uri
                  so you want to join with an empty string:

                  ->on_action(sub { join('', @_)})

                  The other problem with your example is that your method won't be in the
                  correct namespace. You do need something like

                  ->call(SOAP::Data->name('AddItem')->attr({xmlns => 'your namespace'})

                  Regards,
                  Duncan Cameron
                Your message has been successfully submitted and would be delivered to recipients shortly.