Interoperability ASP.NET : Perl using SOAP Web Services

J

josh

Hey All,
I had some Real issues with this stuff over the last week so i thought i
would give anyone interested a heads up...
Josh

Interoperability ASP.NET : Perl using SOAP Web Services.
Introduction
This paper is aimed at those who have a Perl (CGI) script and through the
use of SOAP allow wish to ASP.Net to reference it.

To achieve this you need to create a soap layer around the Perl web service
(I do this using SOAP::lite), then you need to create a WSDL to interface
between the SOAP layer surrounding your Perl script and the soap layer
ASP.NET Uses. Finally add a web reference to the WSDL.

Creating a SOAP layer
NOTE: this is using the SOAP::lite Perl Module (found at www.cpan.com)

Example 1: is some sample Perl code. It is important to note that unlike
JAVA and PERL; ASP.NET is extremely strict on namespaces hence it is
important to give your web service a namespace or the SOAP envelopes will
get lost. The namespace in this example is AxeSMS. The package name in Perl
correlates to the namespace in ASP.NET. Also remember when using the
dispatch line of code that you dispatch to a namespace.

EXAMPLE 1

use SOAP::Transport::HTTP;

SOAP::Transport::HTTP::CGI
-> dispatch_to('AxeSMS')
-> handle;
# die $!;

# AxeSMS.pm - simple module to send SMS via a SOAP inuput
package AxeSMS;

sub sendSMS {
#method
}

Creating the WSDL

For an introduction on WSDL's and how to write them visit
http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarxml/htm
l/wsdlexplained.asp.

This would be an easier step if ASP.NET and Perl shared the same WSDL
principals. Please note the if you were considering using the
WSDL::Generator Perl module also found on cpan then don't bother because
ASP.NET does not like the WSDL's it produces for a variety of reasons.

Example 2 is a complete WSDL that both the Perl and ASP.Net SOAP Layers can
understand.

EXAMPLE 2
<?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="AxeSMS" 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="AxeSMS"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema elementFormDefault="qualified" targetNamespace="AxeSMS">
<s:element name="sendSMS">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="phone"
type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="message"
type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="sendSMSResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="sendSMSResult"
type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</types>
<message name="sendSMSSoapIn">
<part name="parameters" element="s0:sendSMS" />
</message>
<message name="sendSMSSoapOut">
<part name="parameters" element="s0:sendSMSResponse" />
</message>
<portType name="Service1Soap">
<operation name="sendSMS">
<input message="s0:sendSMSSoapIn" />
<output message="s0:sendSMSSoapOut" />
</operation>
</portType>
<binding name="Service1Soap" type="s0:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<operation name="sendSMS">
<soap:blush:peration soapAction="AxeSMS/sendSMS" style="document" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="Service1">
<port name="Service1Soap" binding="s0:Service1Soap">
<soap:address location="http://janus/cgi-bin/sms.cgi" />
</port>
</service>
</definitions>

Some important things to remember when writing the a WSDL for Perl:ASP.Net
Interoperability:
· If you are using some sort of WSDL generation tool then this line
may not be found in your definitions,
xmlns:s="http://www.w3.org/2001/XMLSchema,
it may read as
xmlns:xsd="http://www.w3.org/2001/XMLSchemaI.
ASP.Net does not read the :xsd it uses the :s so you need to change the :xsd
to :s and hence change all of the references through out the rest of the
WSDL.
· xmlns:s0="AxeSMS" this line is needed by ASP.NET, it refers to the
namespace defined in the Perl script.
· The Following attribute must be found in the schema tag
elementFormDefault="qualified".
· Give things in the WSDL unique names.
· Because Perl is a very weekly typed language and ASP.Net is a very
strongly typed language all elements in the schema of the WSDL must be of
type complexType also each Element in the schema must be specifically
specified for example:
<s:element name="sendSMSResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="sendSMSResult"
type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
NOT
<s:element name="sendSMSRequest" type="s:string"/>

Add Web Reference
Using Visual Studio add a web reference the WSDL that you have created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top