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

SOAP::Lite server, .NET Client, WSDL and complexTypes

Expand Messages
  • Perl Median
    I have setup a simple SOAP::Lite server (test.cgi attached) and manually wrote the WSDL (test.wsdl attached) and the C# .NET client (not attached but can be
    Message 1 of 7 , Apr 22, 2004
    • 0 Attachment
      I have setup a simple SOAP::Lite server (test.cgi
      attached) and manually wrote the WSDL (test.wsdl
      attached) and the C# .NET client (not attached but can
      be supplied).

      I can't seem to get it working right though. I assume
      either the WSDL or the SOAP::Data returned is not
      right. The error .NET client returns is:

      System.InvalidCastException: Cannot assign object of
      type System.Xml.XmlNode[] to an object of type
      SoapTesting.testService.returnThings.

      (SoapTesting is the application class, testService is
      the class of the web reference).

      I tried some of the things meantioned in
      http://www.perl.com/lpt/a/2003/03/26/perlanddotnet.html
      but was unsuccessful in making test.cgi use the
      serialize_complex_type subroutine.

      If someone could be so kind as to correct my code or
      point me in the proper direction? Or if someone can
      show my how to implement Tip 4 of the above URL in my
      code or some example code?

      If more info is needed, please let me know. I have
      been trying to get this simple script to work for
      weeks now, all I have successfully done is return a
      single string using similiar WSDL and cgi scripts.
      This script is trying to return 2 strings now, once I
      can do that I think I can write more complexTypes and
      start working on quick tutorial/howto on setting up
      the above situation easily.

      Thank you,
      PerlMedian (AKA Nik J.)

      =====
      Thank you,
      Perl Median (the mediocre Perl Programmer)




      __________________________________
      Do you Yahoo!?
      Yahoo! Photos: High-quality 4x6 digital prints for 25�
      http://photos.yahoo.com/ph/print_splash
    • Matt Long
      Nik, I have been trying to get something like this to work myself, so I dropped your code into a new project in visual studio and gave it a whirl. I am ... An
      Message 2 of 7 , Apr 22, 2004
      • 0 Attachment

        Nik,

         

        I have been trying to get something like this to work myself, so I dropped your code into a new project in visual studio and gave it a whirl. I am getting a different error message than you got. Mine says:

         

        -----------------------------------------------

        An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll

         

        Additional information: There is an error in XML document (2, 106).

        ---------------------------------------------

         

        I’m not sure if that helps. I got it working with a perl client and I’ve attached that script plus the script output. I’m going to try to continue to find the problem as well because this will help me with my own project. Anyhow, let me know if you figure anything else out.

         

        Thanks.

         

        -Matt

         

        p.s. I changed the service port address to reflect my own setup in the testtester.pl file.

         

         

         

        -----Original Message-----
        From: Perl Median [mailto:perlmedian@...]
        Sent:
        Thursday, April 22, 2004 7:13 AM
        To: soaplite@yahoogroups.com
        Subject: [soaplite] SOAP::Lite server, .NET Client, WSDL and complexTypes

         

        I have setup a simple SOAP::Lite server (test.cgi
        attached) and manually wrote the WSDL (test.wsdl
        attached) and the C# .NET client (not attached but can
        be supplied).

        I can't seem to get it working right though. I assume
        either the WSDL or the SOAP::Data returned is not
        right. The error .NET client returns is:

        System.InvalidCastException: Cannot assign object of
        type System.Xml.XmlNode[] to an object of type
        SoapTesting.testService.returnThings.

        (SoapTesting is the application class, testService is
        the class of the web reference).

        I tried some of the things meantioned in
        http://www.perl.com/lpt/a/2003/03/26/perlanddotnet.html
        but was unsuccessful in making test.cgi use the
        serialize_complex_type subroutine.

        If someone could be so kind as to correct my code or
        point me in the proper direction? Or if someone can
        show my how to implement Tip 4 of the above URL in my
        code or some example code?

        If more info is needed, please let me know. I have
        been trying to get this simple script to work for
        weeks now, all I have successfully done is return a
        single string using similiar WSDL and cgi scripts.
        This script is trying to return 2 strings now, once I
        can do that I think I can write more complexTypes and
        start working on quick tutorial/howto on setting up
        the above situation easily.

        Thank you,
        PerlMedian (AKA Nik J.)

        =====
        Thank you,
        Perl Median (the mediocre Perl Programmer)


             
                   
        __________________________________
        Do you Yahoo!?
        Yahoo! Photos: High-quality 4x6 digital prints for 25¢
        http://photos.yahoo.com/ph/print_splash

      • perlmedian
        I didn t know that attachments don t work. Here is the WSDL, next post will have the perlcode:
        Message 3 of 7 , Apr 22, 2004
        • 0 Attachment
          I didn't know that attachments don't work. Here is the WSDL, next post
          will have the perlcode:

          <?xml version="1.0" encoding="UTF-8"?>
          <definitions name="test"
          targetNamespace="urn:test"
          xmlns="http://schemas.xmlsoap.org/wsdl/"
          xmlns:tns="urn:test"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
          xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
          xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <documentation>
          The WSDL Spec for test
          </documentation>

          <types>
          <xsd:schema targetNamespace="urn:test">

          <xsd:complexType name="returnThings">
          <xsd:sequence>
          <xsd:element name="helloResult" type="xsd:string"/>
          <xsd:element name="hostName" type="xsd:string"/>
          </xsd:sequence>
          </xsd:complexType>

          </xsd:schema>
          </types>

          <message name="testFuncRequest">
          <part name="input" type="xsd:string" />
          </message>

          <message name="testFuncResponse">
          <part name="testFuncResult" type="tns:returnThings" />
          </message>

          <portType name="testPort">
          <operation name="testFunc">
          <input message="tns:testFuncRequest" />
          <output message="tns:testFuncResponse" />
          </operation>
          </portType>

          <binding name="SOAP" type="tns:testPort">
          <soap:binding style="rpc"
          transport="http://schemas.xmlsoap.org/soap/http" />

          <operation name="testFunc">
          <soap:operation soapAction="urn:test#testFunc" />

          <input>
          <soap:body use="encoded"
          namespace="urn:test"
          encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
          </input>

          <output>
          <soap:body use="encoded" namespace="urn:test"
          encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
          </output>

          </operation>
          </binding>

          <service name="test">
          <port name="testPort" binding="tns:SOAP">
          <soap:address
          location="http://www/reldistdoc/deliv/external/cgi-bin/soap/test.cgi" />
          </port>
          </service>

          </definitions>
        • perlmedian
          And here s the perl code for the SOAP::Lite server: #!/perl # $Id:$ # $Log:$ ## Packages used use strict; use warnings; use SOAP::Transport::HTTP; ### GLOBAL
          Message 4 of 7 , Apr 22, 2004
          • 0 Attachment
            And here's the perl code for the SOAP::Lite server:

            #!/perl

            # $Id:$
            # $Log:$

            ## Packages used
            use strict;
            use warnings;
            use SOAP::Transport::HTTP;

            ### GLOBAL VARIABLES


            ############################################
            ################## MAIN ##################
            ############################################

            SOAP::Transport::HTTP::CGI
            -> dispatch_to('test')
            -> handle;

            ################ MAIN END ##################



            ############################################
            ############### FUNCTIONS ################
            ############################################


            package test;


            sub testFunc {

            my($self, $input) = @_;

            ### doing my data crunching
            if( not $input ){
            die SOAP::Fault
            ->faultcode('Server.Custom')
            ->faultstring('Nothing sent!')
            ;
            }

            ## this is important you must use type and uri on all items for .NET
            return
            SOAP::Data->name('testFuncResult')->value(
            bless( { hostName => `hostname`,
            helloResult => "Hello $input" }, 'returnThings')
            )->uri('urn:test');
            ;

            } ################################################## END testFunc


            __END__
          • jpeyser
            I had a similar problem using the MS SOAP Toolkit with Excel VBA. The SOAP Toolkit User s Guide states the following in regard to handling complex types.
            Message 5 of 7 , Apr 22, 2004
            • 0 Attachment
              I had a similar problem using the MS SOAP Toolkit with Excel VBA. The
              SOAP Toolkit User's Guide states the following in regard to handling
              complex types.

              "While the SOAP Toolkit knows how to automatically map simple data
              types (an element that contains only text) to an XML type that can be
              included a SOAP message, the toolkit does not know how to
              automatically do this for complex data types (an element that
              contains other elements or attributes). Instead, you have to set up
              this mapping information yourself, using one of the various methods
              described in this section."


              I never tried implementing any of the mappers. Instead, I resorted to
              sending long strings and parsing them on the client side.

              Jonathan

              --- In soaplite@yahoogroups.com, Perl Median <perlmedian@y...> wrote:
              > I have setup a simple SOAP::Lite server (test.cgi
              > attached) and manually wrote the WSDL (test.wsdl
              > attached) and the C# .NET client (not attached but can
              > be supplied).
              >
              > I can't seem to get it working right though. I assume
              > either the WSDL or the SOAP::Data returned is not
              > right. The error .NET client returns is:
              >
              > System.InvalidCastException: Cannot assign object of
              > type System.Xml.XmlNode[] to an object of type
              > SoapTesting.testService.returnThings.
              >
              > (SoapTesting is the application class, testService is
              > the class of the web reference).
              >
              >
            • Perl Median
              Why yes.. here is the code that works for a single string :) Just add web reference.. (point to the wsdl file) and you re ready to go! ... PERL CODE
              Message 6 of 7 , Apr 23, 2004
              • 0 Attachment
                Why yes.. here is the code that works for a single
                string :) Just add web reference.. (point to the wsdl
                file) and you're ready to go!

                --- Matt Long <matt.long@...> wrote:
                > p.s. Do you have an example .NET client and perl
                > server that sends/receives
                > just a scalar successfully? I have yet to get this
                > to work either. If you
                > have something like that, would you be willing to
                > share your code so I can
                > get a better grasp on this stuff? TIA.
                >

                PERL CODE (singleString.cgi):

                #!/u/deliv/perl-5.6.1-unix/bin/perl

                ## Packages used
                use strict;
                use warnings;
                use SOAP::Transport::HTTP;

                ################## MAIN ##################

                SOAP::Transport::HTTP::CGI
                -> dispatch_to('singleString')
                -> handle;

                ################ MAIN END ##################


                package singleString;


                sub singleStringFunc {

                my($self, $input) = @_;

                ### doing my data crunching
                if( not $input ){
                die SOAP::Fault
                ->faultcode('Server.Custom')
                ->faultstring('Nothing sent!')
                ;
                }

                ## this is important you must use type and uri on all
                items for .NET
                return

                SOAP::Data->name('singleStringFuncResult')->value("Hello
                $input")->type('string')->uri('urn:singleString');
                ;

                } ########## END singleStringFunc

                __END__

                ####
                ####
                ####

                AND HERE IS THE WSDL (singleString.wsdl):

                <?xml version="1.0" encoding="UTF-8"?>
                <definitions name="singleString"
                targetNamespace="urn:singleString"
                xmlns="http://schemas.xmlsoap.org/wsdl/"
                xmlns:tns="urn:singleString"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
                xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                <documentation>
                The WSDL Spec for singleString
                </documentation>

                <message name="singleStringFuncRequest">
                <part name="input" type="xsd:string" />
                </message>

                <message name="singleStringFuncResponse">
                <part name="singleStringFuncResult"
                type="xsd:string" />
                </message>

                <portType name="singleStringPort">
                <operation name="singleStringFunc">
                <input message="tns:singleStringFuncRequest" />
                <output message="tns:singleStringFuncResponse" />
                </operation>
                </portType>

                <binding name="SOAP" type="tns:singleStringPort">
                <soap:binding style="rpc"
                transport="http://schemas.xmlsoap.org/soap/http" />

                <operation name="singleStringFunc">
                <soap:operation
                soapAction="urn:singleString#singleStringFunc" />

                <input>
                <soap:body use="encoded"
                namespace="urn:singleString"

                encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                />
                </input>

                <output>
                <soap:body use="encoded"
                namespace="urn:singleString"

                encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                />
                </output>

                </operation>
                </binding>

                <service name="singleString">
                <port name="singleStringPort" binding="tns:SOAP">
                <soap:address
                location="http://www/reldistdoc/deliv/external/cgi-bin/soap/singleString.cgi"
                />
                </port>
                </service>

                </definitions>


                =====
                Thank you,
                Perl Median (the mediocre Perl Programmer)




                __________________________________
                Do you Yahoo!?
                Yahoo! Photos: High-quality 4x6 digital prints for 25�
                http://photos.yahoo.com/ph/print_splash
              • Matt Long
                Nik, I added this code to your complexTypes (returnThings) script: BEGIN { local($^W) = 0; *SOAP::Serializer::gen_ns = sub {}; } and I found that I can
                Message 7 of 7 , Apr 23, 2004
                • 0 Attachment
                  Nik,

                  I added this code to your complexTypes (returnThings) script:

                  BEGIN {
                  local($^W) = 0;
                  *SOAP::Serializer::gen_ns = sub {};
                  }

                  and I found that I can actually connect to the service without any errors
                  since it overrides adding the namsp1 values. The only problem now is that
                  the return values in the returnThings object are null. I'm not sure what the
                  problem is at this point.

                  Anyhow, thanks for sharing your code with me. I'll play around with that as
                  well and we'll see what happens. Not sure about you, but I'm pretty
                  frustrated. Hopefully perseverance will pay off. ;-)

                  Thanks.

                  -Matt
                Your message has been successfully submitted and would be delivered to recipients shortly.