Sponsored Links
SOA Web Services Tutorials
- SOA Web Services - SOA and Web Services Approach for Integration
- SOA Web Services - SOA Evolution
- SOA Web Services - IT Evolution
- SOA Web Services - Patterns
- SOA Web Services - Designing Sound Web Services
- SOA Web Services - Self-Service Business Pattern
- SOA Web Services - Extended Enterprise Business Pattern
- SOA Web Services - Application Integration Pattern
- SOA Web Services - Direct Connection Application Pattern
- SOA Web Services - Broker Application Pattern
- SOA Web Services - Serial Process Application Pattern
- SOA Web Services - Parallel Process Application Pattern
- SOA Web Services - Runtime Patterns
- SOA Web Services - Direct Connection Runtime Pattern
- SOA Web Services - Direct Connection Pattern
- SOA Web Services - Runtime Patterns for Broker
- SOA Web Services - Differences between B2B and EAI Web Services
- SOA Web Services - Writing Interoperable WSDL Definitions
- SOA Web Services - Validating Interoperable WSDL
- SOA Web Services - WS-I Specifications
Tutorials
SOA Web ServicesSOA Web Services - Developing the .NET Web Service
Developing the .NET Web Service
Creating a .NET web service using Visual Studio IDE is as simple as creating a Java web service using NetBeans IDE. I used Visual Studio 2005 for creating the web service and the test client application. The IDE provides a template for creating an ASP.NET Web Service.
Follow the default project options while creating the web service. I used the NetService as the name for my project and selected C# as the development language. The wizard generates a default class for the web service with a default service method. I modified this service method to send a greeting message to the caller. The modified source file is shown in the following listing.
- using System
- using System.Web
- using System.Web.Services
- using System.Web.Services.Protocols
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- public class Service : System.Web.Services.WebService
- {
- public Service () {
- //Uncomment the following line if using designed components
- //InitializeComponent()
- }
- [WebMethod]
- public string SayHello() {
- return "\nHello from .NET service"
- }
- }
As can be seen from the listing, the Service class inherits from the System.Web. Services.WebServiceclass. The class is attributed with two attributes WebService and WebServiceBinding. The WebServiceattribute specifies the namespace for the defined web service. The WebServiceBinding attribute defines the conformance target.
In our example, the conformance target is Basic Profile 1.1 as specified by the constant from the WsiProfiles class. Within the class definition, each desired method that is to be invoked as a web service method should be annotated using the WebMethod keyword. In our example, the SayHello method is declared as a web method that can be invoked using SOAP.
Deploying the .NET Web Service
Once you write the code for the web service, it can be deployed using the wizard provided in the VS.NET IDE. You may now look up the generated WSDL by opening the following URL in your browser:
http://localhost:20278/NetService/Service.asmx?WSDL
Note that you will need to set up the appropriate port number in the above URL. The generated WSDL is shown in following listing.
- <wsdl:definitions targetnamespace="http://tempuri.org/">
- <wsdl:types>
- <s:schema targetnamespace="http://
- tempuri.org/" elementformdefault="qualified">
- <s:element name="SayHello">
- <s:complextype></s:complextype>
- </s:element>
- <s:element name="SayHelloResponse">
- <s:complextype>
- <s:sequence>
- <s:element name="SayHelloResult" type="s:
- string" minoccurs="0" maxoccurs="1"></s:element>
- </s:sequence>
- </s:complextype>
- </s:element>
- </s:schema>
- </wsdl:types>
- <wsdl:message name="SayHelloSoapIn">
- <wsdl:part name="parameters" element="tns:SayHello"></wsdl:part>
- </wsdl:message>
- <wsdl:message name="SayHelloSoapOut">
- <wsdl:part name="parameters" element="tns:SayHelloResponse"></wsdl:part>
- </wsdl:message>
- <wsdl:porttype name="ServiceSoap">
- <wsdl:operation name="SayHello">
- <wsdl:input message="tns:SayHelloSoapIn" />
- <wsdl:output message="tns:SayHelloSoapOut"></wsdl:output>
- </wsdl:operation>
- </wsdl:porttype>
- <wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
- <soap:binding transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
- <wsdl:operation name="SayHello">
- <soap:operation soapaction="http://tempuri.org/SayHello"></soap:operation>
- <wsdl:input>
- <soap:body use="literal"></soap:body>
- </wsdl:input>
- <wsdl:output>
- <soap:body use="literal"></soap:body>
- </wsdl:output>
- </wsdl:operation>
- </wsdl:binding>
- <wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap">
- <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"></soap12:binding>
- <wsdl:operation name="SayHello">
- <soap12:operation soapaction="http://tempuri.org/SayHello"></soap12:operation>
- <wsdl:input>
- <soap12:body use="literal"></soap12:body>
- </wsdl:input>
- <wsdl:output>
- <soap12:body use="literal"></soap12:body>
- </wsdl:output>
- </wsdl:operation>
- </wsdl:binding>
- <wsdl:service name="Service">
- <wsdl:port name="ServiceSoap" binding="tns:ServiceSoap">
- <soap:address location="http://localhost:20278/NetService/Service.
- asmx"></soap:address>
- </wsdl:port>
- <wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12">
- <soap12:address location="http://localhost:20278/NetService/Service.
- asmx"></soap12:address>
- </wsdl:port>
- </wsdl:service>
- </wsdl:definitions>
If you compare this WSDL against the BP conformance requirements, you will find that this is indeed BP 1.1 conformant.
Comments
Sponsored Links
