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

soap headers

Expand Messages
  • Mike
    I am trying to access a sms service using soap::lite The xml that the service is expecting is : soap:Envelope
    Message 1 of 7 , Jun 25, 2003
      I am trying to access a sms service using soap::lite

      The xml that the service is expecting is :

      soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Header>
      <MessengerHeader xmlns="com.esendex.ems.soapinterface">
      <Username>USERNAME</Username>
      <Password>PASSWORD</Password>
      <Account>ACCOUNT</Account>
      </MessengerHeader>
      </soap:Header>
      <soap:Body>
      <SendMessageFull xmlns="com.esendex.ems.soapinterface">
      <originator>ORIGINATOR</originator>
      <recipient>RECIPIENT</recipient>
      <body>test message</body>
      <type>Text</type>
      <validityperiod>int</validityperiod>
      </SendMessageFull>
      </soap:Body>
      </soap:Envelope>


      is there any way using soap::lite to create this format ?

      as you can see from the above that the header is in the format

      <messengerheader>
      <username></username>
      <password></password>
      </messengerheader>

      I can not work out how to acheive this layout using soap::lite

      any help will be much appreciated

      so far, with a lot of help, i have created the following perl script

      use SOAP::Lite +trace => debug, on_action => sub {sprintf '%s/%s',
      @_};


      use strict;
      my $username = "username";
      my $password = "password";
      my $account = "account";
      my $originator = "orig";
      my $recipient = "recip";
      my $body = "TEST SOAP";
      my $type = "text";
      my $host = 'www.esendex.com';
      #my $host = "nott2.esendex.com:8080";
      my $proxy = "http://$host/secure/messenger/soap/SendService.asmx";
      my $uri = "com.esendex.ems.soapinterface";

      #The name of the module
      my $soap = SOAP::Lite->uri($uri);

      #The url for the request
      $soap = $soap->proxy($proxy);

      # send the request w/ header
      my $response = $soap->SendMessageFull(

      # HEADER
      SOAP::Header->name(Username => $username),
      SOAP::Header->name(Password => $password),
      SOAP::Header->name(Account => $account),

      # PARAMETERS FOR BODY
      SOAP::Data->name(originator =>$originator),
      SOAP::Data->name(recipient => $recipient),
      SOAP::Data->name(body => $body),
      SOAP::Data->name(type =>$type),
      SOAP::Data->name(validityperiod => 99)

      );

      print "response = $response\n";

      # get the result and print the error message if it failed
      if (defined (my $result = $response->result)) {
      print "result = $result\n";
      }
      else {
      print "Fault: ", $response->faultstring, "\n",
      "Detail:\n", $response->faultdetail, "\n";
      }


      this generates the following xml

      <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-
      instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"
      SOAP-
      ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-
      ENV:Header><Username
      xsi:type="xsd:string">mike.solomon@...</Username>
      <Password xsi:type="xsd:string">events</Password>
      <Account xsi:type="xsd:int">447800140755</Account>
      </SOAP-ENV:Header>
      <SOAP-ENV:Body>
      <namesp1:SendMessageFull
      xmlns:namesp1="com.esendex.ems.soapinterface">
      <originator xsi:type="xsd:int">07939717376</originator>
      <recipient xsi:type="xsd:int">07939717376</recipient>
      <body xsi:type="xsd:string">TEST SOAP</body>
      <type xsi:type="xsd:string">text</type>
      <validityperiod xsi:type="xsd:int">99</validityperiod>
      </namesp1:SendMessageFull>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>


      Regards

      Mike Solomom
    • Randy J. Ray
      (replied to author privately, then realized I forgot to Cc the list) You are close, but as you noted, the result is three separate elements within ... What
      Message 2 of 7 , Jun 25, 2003
        (replied to author privately, then realized I forgot to Cc the list)

        You are close, but as you noted, the result is three separate elements within
        the Header block, each named for your elements below:

        > # send the request w/ header
        > my $response = $soap->SendMessageFull(
        >
        > # HEADER
        > SOAP::Header->name(Username => $username),
        > SOAP::Header->name(Password => $password),
        > SOAP::Header->name(Account => $account),
        >
        > # PARAMETERS FOR BODY
        > SOAP::Data->name(originator =>$originator),
        > SOAP::Data->name(recipient => $recipient),
        > SOAP::Data->name(body => $body),
        > SOAP::Data->name(type =>$type),
        > SOAP::Data->name(validityperiod => 99)
        >
        > );

        What your service is expecting is a single header entity called
        "MessengerHeader" that itself contains those three elements. Something more
        like:

        SOAP::Header->name(MessengerHeader => { Username => $username,
        Password => $password,
        Account => $account })

        However, I think that the above will serialize strangely because of the
        defaults applied to non-blessed hash references. See my article on .Net
        programming in Perl:

        http://www.perl.com/pub/a/2003/03/26/perlanddotnet.html

        This is very similar to the biggest headache in .Net-- getting serialized
        structures to match what .Net is expecting. There's a recipe for a generalized
        structure-encoding approach that should be adaptable to what you're doing.

        Randy
        --
        rjray@... http://www.rjray.org http://www.svsm.org

        Any spammers auto-extracting addresses from this message will definitely want
        to include uce@... and report@...
      • Mike Solomon
        Thanks for this Unfortunately it does not solve my problem In the header I need the following:
        Message 3 of 7 , Jun 26, 2003
          Thanks for this

          Unfortunately it does not solve my problem

          In the header I need the following:

          <soap:Header>
          <MessengerHeader xmlns="com.esendex.ems.soapinterface">
          <Username>USERNAME</Username>
          <Password>PASSWORD</Password>
          <Account>ACCOUNT</Account>
          </MessengerHeader>
          </soap:Header>

          I can now get

          <SOAP-ENV:Header><MessengerHeader>
          <Username xsi:type="xsd:string">USERNAME</Username>
          <Password xsi:type="xsd:string">PASSWORD</Password>
          <Account xsi:type="xsd:int">ACCOUNT</Account>
          </MessengerHeader></SOAP-ENV:Header>

          using

          SOAP::Header->new(name => 'MessengerHeader', value =>
          \SOAP::Header->value(

          SOAP::Header->name(Username => $username),
          SOAP::Header->name(Password => $password),
          SOAP::Header->name(Account => $account),

          ) ),

          but this doesn't work



          Regards

          Mike Solomon
          mike_solomon@...


          -----Original Message-----
          From: jpeyser [mailto:jpeyser@...]
          Sent: 25 June 2003 20:25
          To: Mike
          Subject: Re: soap headers

          Mike,

          Try the following.

          $MsgFull = [
          SOAP::Data->name(Username => $username),
          SOAP::Data->name(Password => $password),
          SOAP::Data->name(Account => $account),
          )];

          # send the request w/ header
          my $response = $soap->SendMessageFull(

          # HEADER
          SOAP::Header->name(MessengerHeader => $MsgFull),
        • Mike Solomon
          Thanks for your help I read the article but I don t think it helped me It probably would if I understood it better I am trying to get the following
          Message 4 of 7 , Jun 26, 2003
            Thanks for your help

            I read the article but I don't think it helped me

            It probably would if I understood it better

            I am trying to get the following

            <soap:Header>
            <MessengerHeader xmlns="com.esendex.ems.soapinterface">
            <Username>USERNAME</Username>
            <Password>PASSWORD</Password>
            <Account>ACCOUNT</Account>
            </MessengerHeader>
            </soap:Header>

            I have managed to get most of it but can't achieve
            xmlns="com.esendex.ems.soapinterface

            I am wondering if I would be better off abandoning soap:lite and finding
            another way of sending the xml


            Regards

            Mike Solomon

            -----Original Message-----
            From: Randy J. Ray [mailto:rjray@...]
            Sent: 26 June 2003 05:15
            To: Mike
            Subject: Re: [soaplite] soap headers

            You are close, but as you noted, the result is three separate elements
            within
            the Header block, each named for your elements below:

            > # send the request w/ header
            > my $response = $soap->SendMessageFull(
            >
            > # HEADER
            > SOAP::Header->name(Username => $username),
            > SOAP::Header->name(Password => $password),
            > SOAP::Header->name(Account => $account),
            >
            > # PARAMETERS FOR BODY
            > SOAP::Data->name(originator =>$originator),
            > SOAP::Data->name(recipient => $recipient),
            > SOAP::Data->name(body => $body),
            > SOAP::Data->name(type =>$type),
            > SOAP::Data->name(validityperiod => 99)
            >
            > );

            What your service is expecting is a single header entity called
            "MessengerHeader" that itself contains those three elements. Something
            more
            like:

            SOAP::Header->name(MessengerHeader => { Username => $username,
            Password => $password,
            Account => $account })

            However, I think that the above will serialize strangely because of the
            defaults applied to non-blessed hash references. See my article on .Net
            programming in Perl:

            http://www.perl.com/pub/a/2003/03/26/perlanddotnet.html

            This is very similar to the biggest headache in .Net-- getting
            serialized
            structures to match what .Net is expecting. There's a recipe for a
            generalized
            structure-encoding approach that should be adaptable to what you're
            doing.

            Randy
            --
          • jpeyser
            Mike, Things are not always straightforward, but there is always a way to do it in Perl. Sometimes, you have to hack a little. Here is the code to generate the
            Message 5 of 7 , Jun 26, 2003
              Mike,
              Things are not always straightforward, but there is always a way
              to do it in Perl. Sometimes, you have to hack a little. Here is the
              code to generate the SOAP/XML with it's own serializer (that
              redefines a couple of subroutines from SOAP::Serializer).

              Jonathan

              #--------------------------------
              #!/usr/local/bin/perl

              use SOAP::Lite;
              use strict;

              BEGIN {
              package My::Serializer;

              use SOAP::Lite;

              @My::Serializer::ISA = qw(SOAP::Serializer);

              ### Suppress autotyping
              sub autotype {
              my $self = shift;

              return;
              }

              ### Suppress autotyping for arrays
              sub encode_array {
              my($self, $array, $name, $type, $attr) = @_;
              my $items = 'item';

              ### TD: add support for multidimensional, partially
              transmitted and sparse arrays
              my @items = map {$self->encode_object($_, $items)} @$array;
              my $num = @items;
              my($arraytype, %types) = '-';
              for (@items) { $arraytype = $_->[1]->{'xsi:type'} || '-';
              $types{$arraytype}++ }
              $arraytype = sprintf "%s\[$num]", keys %types > 1 ||
              $arraytype eq '-' ? SOAP::Utils::qualify(xsd => $self->xmlschemaclass-
              >anyTypeValue) : $arraytype;

              $type = SOAP::Utils::qualify($self->encprefix => 'Array') if
              $self->autotype && !defined $type;

              return [$name || SOAP::Utils::qualify($self->encprefix
              => 'Array'),
              # {SOAP::Utils::qualify($self->encprefix => 'arrayType') =>
              $arraytype, 'xsi:type' => $self->maptypetouri($type), %$attr},
              {'xsi:type' => $self->maptypetouri($type), %
              $attr},
              [@items],
              $self->gen_id($array)
              ];
              }
              }

              my $username = "username";
              my $password = "password";
              my $account = "account";
              my $originator = "orig";
              my $recipient = "recip";
              my $body = "TEST SOAP";
              my $type = "text";
              my $host = 'www.esendex.com';
              my $proxy = "http://$host/secure/messenger/soap/SendService.asmx";
              my $uri = "com.esendex.ems.soapinterface";

              #The name of the module
              my $soap = SOAP::Lite
              ->uri($uri)
              ->proxy($proxy)
              ->serializer(My::Serializer->new)
              ->envprefix('soap');

              my $MsgFull = [
              SOAP::Data->name(Username => $username),
              SOAP::Data->name(Password => $password),
              SOAP::Data->name(Account => $account),
              ];

              # send the request w/ header
              my $response = $soap->SendMessageFull(

              # HEADER
              SOAP::Header->name(MessengerHeader => $MsgFull)->attr
              ({'xmlns'=> 'com.esendex.ems.soapinterface'}),

              # PARAMETERS FOR BODY
              SOAP::Data->name(originator =>$originator),
              SOAP::Data->name(recipient => $recipient),
              SOAP::Data->name(body => $body),
              SOAP::Data->name(type =>$type),
              SOAP::Data->name(validityperiod => 99)
              );

              print "response = $response\n";

              # get the result and print the error message if it failed
              if (defined (my $result = $response->result)) {
              print "result = $result\n";
              }
              else {
              print "Fault: ", $response->faultstring, "\n",
              "Detail:\n", $response->faultdetail, "\n";
              }




              --- In soaplite@yahoogroups.com, "Mike Solomon" <mike_solomon@l...>
              wrote:
              > Thanks for your help
              >
              > I read the article but I don't think it helped me
              >
              > It probably would if I understood it better
              >
              > I am trying to get the following
              >
              > <soap:Header>
              > <MessengerHeader xmlns="com.esendex.ems.soapinterface">
              > <Username>USERNAME</Username>
              > <Password>PASSWORD</Password>
              > <Account>ACCOUNT</Account>
              > </MessengerHeader>
              > </soap:Header>
              >
              > I have managed to get most of it but can't achieve
              > xmlns="com.esendex.ems.soapinterface
              >
              > I am wondering if I would be better off abandoning soap:lite and
              finding
              > another way of sending the xml
              >
              >
              > Regards
              >
              > Mike Solomon
              >
              > -----Original Message-----
              > From: Randy J. Ray [mailto:rjray@b...]
              > Sent: 26 June 2003 05:15
              > To: Mike
              > Subject: Re: [soaplite] soap headers
              >
              > You are close, but as you noted, the result is three separate
              elements
              > within
              > the Header block, each named for your elements below:
              >
              > > # send the request w/ header
              > > my $response = $soap->SendMessageFull(
              > >
              > > # HEADER
              > > SOAP::Header->name(Username => $username),
              > > SOAP::Header->name(Password => $password),
              > > SOAP::Header->name(Account => $account),
              > >
              > > # PARAMETERS FOR BODY
              > > SOAP::Data->name(originator =>$originator),
              > > SOAP::Data->name(recipient => $recipient),
              > > SOAP::Data->name(body => $body),
              > > SOAP::Data->name(type =>$type),
              > > SOAP::Data->name(validityperiod => 99)
              > >
              > > );
              >
              > What your service is expecting is a single header entity called
              > "MessengerHeader" that itself contains those three elements.
              Something
              > more
              > like:
              >
              > SOAP::Header->name(MessengerHeader => { Username => $username,
              > Password => $password,
              > Account => $account })
              >
              > However, I think that the above will serialize strangely because of
              the
              > defaults applied to non-blessed hash references. See my article
              on .Net
              > programming in Perl:
              >
              > http://www.perl.com/pub/a/2003/03/26/perlanddotnet.html
              >
              > This is very similar to the biggest headache in .Net-- getting
              > serialized
              > structures to match what .Net is expecting. There's a recipe for a
              > generalized
              > structure-encoding approach that should be adaptable to what you're
              > doing.
              >
              > Randy
              > --
            • Randy J. Ray
              ... When you create the SOAP::Header object, you can also call an attr method on it, to specify that is should have an attribute of xmlns whose value is
              Message 6 of 7 , Jun 26, 2003
                On 2003.06.26 08:15, Mike Solomon wrote:

                > I have managed to get most of it but can't achieve
                > xmlns="com.esendex.ems.soapinterface

                When you create the SOAP::Header object, you can also call an "attr" method on
                it, to specify that is should have an attribute of "xmlns" whose value is
                "com.esendex.ems.soapinterface".

                Randy
                --
                """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
                Randy J. Ray Campbell, CA http://www.rjray.org rjray@blackperl.
                com

                Silicon Valley Scale Modelers: http://www.svsm.org
              • Paul Kulchenko
                Mike, use SOAP::Lite maptype = {}; my $messageHeader = SOAP::Header- name(MessageHeader = { Username = SOAP::Data- type( = USERNAME ), Password =
                Message 7 of 7 , Jun 27, 2003
                  Mike,

                  use SOAP::Lite maptype => {};

                  my $messageHeader = SOAP::Header->name(MessageHeader => {
                  Username => SOAP::Data->type('' => 'USERNAME'),
                  Password => SOAP::Data->type('' => 'PASSWORD'),
                  Account => SOAP::Data->type('' => 'ACCOUNT'),
                  })->uri("com.esendex.ems.soapinterface")->prefix('');

                  Will give you exactly the code you want to see. prefix('') will
                  generate "xmlns=" instead of "xmlns:ns1=".

                  This example is included in "Programming Web Services with Perl"
                  (p284). The documentation will be updated to include that too.

                  Best wishes, Paul.

                  --- Mike Solomon <mike_solomon@...> wrote:
                  > Thanks for your help
                  >
                  > I read the article but I don't think it helped me
                  >
                  > It probably would if I understood it better
                  >
                  > I am trying to get the following
                  >
                  > <soap:Header>
                  > <MessengerHeader xmlns="com.esendex.ems.soapinterface">
                  > <Username>USERNAME</Username>
                  > <Password>PASSWORD</Password>
                  > <Account>ACCOUNT</Account>
                  > </MessengerHeader>
                  > </soap:Header>
                  >
                  > I have managed to get most of it but can't achieve
                  > xmlns="com.esendex.ems.soapinterface
                  >
                  > I am wondering if I would be better off abandoning soap:lite and
                  > finding
                  > another way of sending the xml
                  >
                  >
                  > Regards
                  >
                  > Mike Solomon
                  >
                  > -----Original Message-----
                  > From: Randy J. Ray [mailto:rjray@...]
                  > Sent: 26 June 2003 05:15
                  > To: Mike
                  > Subject: Re: [soaplite] soap headers
                  >
                  > You are close, but as you noted, the result is three separate
                  > elements
                  > within
                  > the Header block, each named for your elements below:
                  >
                  > > # send the request w/ header
                  > > my $response = $soap->SendMessageFull(
                  > >
                  > > # HEADER
                  > > SOAP::Header->name(Username => $username),
                  > > SOAP::Header->name(Password => $password),
                  > > SOAP::Header->name(Account => $account),
                  > >
                  > > # PARAMETERS FOR BODY
                  > > SOAP::Data->name(originator =>$originator),
                  > > SOAP::Data->name(recipient => $recipient),
                  > > SOAP::Data->name(body => $body),
                  > > SOAP::Data->name(type =>$type),
                  > > SOAP::Data->name(validityperiod => 99)
                  > >
                  > > );
                  >
                  > What your service is expecting is a single header entity called
                  > "MessengerHeader" that itself contains those three elements.
                  > Something
                  > more
                  > like:
                  >
                  > SOAP::Header->name(MessengerHeader => { Username => $username,
                  > Password => $password,
                  > Account => $account
                  > })
                  >
                  > However, I think that the above will serialize strangely because of
                  > the
                  > defaults applied to non-blessed hash references. See my article on
                  > .Net
                  > programming in Perl:
                  >
                  > http://www.perl.com/pub/a/2003/03/26/perlanddotnet.html
                  >
                  > This is very similar to the biggest headache in .Net-- getting
                  > serialized
                  > structures to match what .Net is expecting. There's a recipe for a
                  > generalized
                  > structure-encoding approach that should be adaptable to what you're
                  > doing.
                  >
                  > Randy
                  > --
                  >
                  >
                  >
                  > ------------------------ Yahoo! Groups Sponsor
                  >
                  > To unsubscribe from this group, send an email to:
                  > soaplite-unsubscribe@yahoogroups.com
                  >
                  >
                  >
                  > Your use of Yahoo! Groups is subject to
                  > http://docs.yahoo.com/info/terms/
                  >
                  >


                  __________________________________
                  Do you Yahoo!?
                  SBC Yahoo! DSL - Now only $29.95 per month!
                  http://sbc.yahoo.com
                Your message has been successfully submitted and would be delivered to recipients shortly.