http://www.perlmonks.org?node_id=746705

joec_ has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I have a question regarding accessing a soap webservice from within a browser.

I have set up a webservice as per the example on the soap lite website and this works fine from within a terminal. But when i call either my soap client 'hibye.pl' or my cgi script Demo.cgi, from within a browser, i get 500 internal server errors.

I think i am doing something wrong....

Thanks for the help

joe

-----

Eschew obfuscation, espouse eludication!

Replies are listed 'Best First'.
Re: Webservices and browsers
by jhourcle (Prior) on Feb 27, 2009 at 02:11 UTC

    The hibye.pl scrpt is not a CGI -- it doesn't emit HTTP headers (Content-type).

    A web browser is not a SOAP client -- it doesn't emit the necessary HTTP headers (SOAPAction) or send a SOAP message.

    If you want to write a CGI that's also a SOAP client, that's fine -- but you can't just throw any old executable on a webserver and expect it to work.

    Try the following.

    use CGI; print CGI-header; use SOAP::Lite; print SOAP::Lite -> uri('http://www.soaplite.com/Demo') -> proxy('') # set this to your SOAP service URL -> hi() -> result;
      Hi,

      Can you tell me if it is possible to consume a perl webservice from within .NET (C#)? Obviously, these simple perl web services dont use WSDLs or XML because, when for example i try to access my web service from C#, i get an error message stating that XML was expected and it "received text/plain" - this was using the example service on the soap lite site, which just returned a simple string and not a SOAP envelope?!.

      I am new to web services and think i need some clarification

      Any help appreciated

      Thanks --Joe

      -----

      Eschew obfuscation, espouse eludication!

        The text/plain thing sounds like a problem -- make sure that the CGI is actually executing, and not just the file being returned.

        I've run into a few problems when people tried consuming a SOAP::Lite service using a strictly typed language, and I had to do some work in making sure it serialized correctly -- I had a few items that were strings of numbers, and SOAP::Lite kept marking it as numbers -- I was using RPC/encoded SOAP, and not using SOAP::Data to declare what the values were, as I was getting them from another SOAP call. In the end, I replaced SOAP::Serializer to make sure it sent what I wanted.

        I believe that issues of compatibility have come up in the past on the soaplite mailing list -- you might check their archives, but it's also possible that it's no longer an issue as they've moved away from the overhead of RPC/encoded messages.

Re: Webservices and browsers
by olus (Curate) on Feb 26, 2009 at 23:53 UTC

    You should check your error log for information on what is going on. If everything works fine from the command line then maybe you have permissions issues, or maybe different Perl installations, or your scripts aren't executable....

      The scripts are executable...what should i put in the browser though? Demo.cgi or hibye.pl? Demo.cgi is the soap server and hibye.pl is the client....

      Nothing obvious in error logs either.

      How can i obtain a WSDL for the web service as well?

      Thanks

      -----

      Eschew obfuscation, espouse eludication!

        Nothing obvious in error logs either.

        Nevertheless it would be good to know what is being written there.

        When you set up a webservice, you are probably interested in accessing the server's methods from wherever, so your web application is one more client. What you need to call is the client script.

        If everything works fine from the command line, then all you need to care about is sending the information you get from the server into the browser. Since I don't know your code, I can only guess that maybe you are forgetting to send the content-type header to the browser?

        update The content-type be text/html. Before you send anything to the browser you must print "Content-Type: text/html\n\n";

        The WSDL describes the service being provided, its methods, data types, how to reach it, etc. Read WSDL Tutorial for an understanding about its purpose and syntax.