MrBool
You must be logged in to give feedback. Click here to login
[Close]

You must be logged to download.

Click here to login

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Web Services: Simple Object Access Protocol (SOAP)

This article will discuss about SOAP Web Services, its importance and usage along with an example.

[close]

You didn't like the quality of this content?

Would you like to comment what you didn't like?

Introduction:

SOAP is a basic XML based protocol which basically allows the applications in order to exchange the information over Hyper Text Transfer Protocol (HTTP) and this protocol helps in accessing the web service. The usage of web service in an application converts the application into a web-based application. XML is used in order to send the messages between different applications. XML and HTTP are used to access a web service. Web Service Description Language (WSDL) is an Extensible Markup Language (XML) based language format used to describe the services of network or web and the method of accessing these kinds of services. It is an XML document used to describe and find the location of web services. The document contains information and this information is used to know about the necessary details about the specific topic and it contains the total description about the specific web service. A directory services known as Universal Description, Discovery and Integration (UDDI) which is used by different businesses in order to search and register to get the web services and access them. This directory is used to store the information about the related web services which are required to be used. UDDI is not dependent on any platform and it can be used in any platform in order to describe the services of business, discovering them and integrating the services by the use of the internet. This UDDI directory of web service interfaces is described by the WSDL and UDDI communicates through SOAP.

Description:

SOAP is a protocol used for the communication. It is a format used in order to send to send the messages and the communication is done through Internet. It is independent of language and platform, simple and can be extended. An application can have a component of web service and it can be created without any particular language of programming. A WSDL document written in XML contains different types of elements. The basic elements used by WSDL include <types>, <message>, <port-Type> and <binding>. It also contains some other elements including extension and service elements. The binding element present in WSDL defines the format of messages and the details of protocol used in order to access a web service. This binding element consists of attributes including the name and the type. The binding used by Simple Object Access Protocol (SOAP) consists of attributes including style and transport. The style attribute can be a kind of document and the transport attribute basically defines the protocol of SOAP in order to use it. The action to be performed by SOAP is required to be defined properly in order to use and access the services. SOAP is an important protocol for the development of applications in order to allow the connection of internet between different programs. In order to establish the communication successfully between applications, this is done through HTTP as this protocol is supported by any browser. The SOAP message contains the elements including envelope, header, body and fault. All of these elements provide specific information and are used for proper communication depending on the needs and requirements. SOAP method is basically the request and response of HTTP and which is compiled using the encoding rules present with this protocol. The request message of SOAP can be HTTP GET or HTTP POST depending on the requirements of the application to be considered at a particular point of time.

Overview:

In the SOAP based web services, a file of WSDL is created in the web service and on the code of java using the java utilities. The parties either two or more which are interested in using a web service create a java client respectively that is basically based on the WSDL. In SOAP protocol, the message communication and exchange is done using the format of this protocol. The basis of a web service is XML which basically provides the language that is usable by different platforms and the programming languages and it is able to show the complex messages and functions. HTTP is an internet protocol that is used mostly in order to browse and surf the web. Through the web, the web services can be used and found present in a web application. The discovery of web services is done by using UDDI. The communication of web services is done and completed by using the open and accessible protocols. The Java API for XML web services (JAX-WS) is the technology used in order to build the web services using XML. The message oriented services of web can be written using JAX-WS. This JAX-WS API has the ability to hide the complexity of SOAP from the developer of the respective application. The developer makes the operations of web service specified after defining the methods present in an interface and the web service of java. The java web service is JAX-WS runtime system which basically converts the calls of API and gives response to and from the messages of SOAP. The @WebService annotation is used to show that the web service is being used in the respective class and @WebMethod is used to show that the service of web is present in the function. There is a need of a constructor in the class in which the web service is required to be used and the constructor to be present can be a default, public and without arguments.

Importance:

SOAP provides an excellent method to communicate between applications which are actually running on separate and different operating systems including different and complex technologies and programming languages. The platform elements of web services include SOAP, UDDI and WSDL. By using the web service, an application can show and describe the function and message to the whole world in an easy manner. One example of web service is to offer the translation of language of a webpage as a service. The SOAP based web services are good for complex and heavy applications which can use different operations and the application which basically needs the security, reliability and related features of web services standards that are supported.

Screenshots:

This is the main interface of the web service when the SOAP based web application is created.

Web Application named as soap_working and its interface

Figure 1: Web Application named as soap_working and its interface

This is an interface which takes the form when the two new functional operations are added. This is basically the design of the main application and type of web service.

Interface with three Operations to be performed as Web Service to Client

Figure 2: Interface with three Operations to be performed as Web Service to Client

Implementation & Code: SOAP Web Services with JAX-WS

Listing 1 wsit-soappackage.soap_working:

<?xml version="1.0" encoding="UTF-8"?> 
 <definitions 
 xmlns="http://schemas.xmlsoap.org/wsdl/" 
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="soap_working" targetNamespace="http://soappackage/" xmlns:tns="http://soappackage/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsrm="http://docs.oasis-open.org/ws-rx/wsrmp/200702" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy" 
 >
    <message name="hello"/>
    <message name="helloResponse"/>
    <message name="conversion_from_pounds_to_usd"/>
    <message name="conversion_from_pounds_to_usdResponse"/>
    <message name="conversion_from_usd_to_pounds"/>
    <message name="conversion_from_usd_to_poundsResponse"/>
    <portType name="soap_working">
        <operation name="hello">
            <input message="tns:hello"/>
            <output message="tns:helloResponse"/>
        </operation>
        <operation name="conversion_from_pounds_to_usd">
            <input message="tns:conversion_from_pounds_to_usd"/>
            <output message="tns:conversion_from_pounds_to_usdResponse"/>
        </operation>
        <operation name="conversion_from_usd_to_pounds">
            <input message="tns:conversion_from_usd_to_pounds"/>
            <output message="tns:conversion_from_usd_to_poundsResponse"/>
        </operation>
    </portType>
    <binding name="soap_workingPortBinding" type="tns:soap_working">
        <wsp:PolicyReference URI="#soap_workingPortBindingPolicy"/>
        <operation name="hello">
            <input>
                <wsp:PolicyReference URI="#soap_workingPortBinding_hello_Input_Policy"/>
            </input>
            <output>
                <wsp:PolicyReference URI="#soap_workingPortBinding_hello_Output_Policy"/>
            </output>
        </operation>
        <operation name="conversion_from_pounds_to_usd">
            <input>
                <wsp:PolicyReference URI="#soap_workingPortBinding_hello_Input_Policy"/>
            </input>
            <output>
                <wsp:PolicyReference URI="#soap_workingPortBinding_hello_Output_Policy"/>
            </output>
        </operation>
        <operation name="conversion_from_usd_to_pounds">
            <input>
                <wsp:PolicyReference URI="#soap_workingPortBinding_hello_Input_Policy"/>
            </input>
            <output>
                <wsp:PolicyReference URI="#soap_workingPortBinding_hello_Output_Policy"/>
            </output>
        </operation>
    </binding>
    <service name="soap_working">
        <port name="soap_workingPort" binding="tns:soap_workingPortBinding"/>
    </service>
    <wsp:Policy wsu:Id="soap_workingPortBindingPolicy">
        <wsp:ExactlyOne>
            <wsp:All>
                <wsoma:OptimizedMimeSerialization/>
                <wsam:Addressing wsp:Optional="false"/>
                <wsrm:RMAssertion/>
                <sp:SymmetricBinding>
                    <wsp:Policy>
                        <sp:ProtectionToken>
                            <wsp:Policy>
                                <sp:SecureConversationToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
                                    <wsp:Policy>
                                        <sp:RequireDerivedKeys/>
                                        <sp:BootstrapPolicy>
                                            <wsp:Policy>
                                                    <sp:AsymmetricBinding>
                                                            <wsp:Policy>
                                                                    <sp:InitiatorToken>
                                                                            <wsp:Policy>
                                                                                    <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
                                                                                            <wsp:Policy>
                                                                                                    <sp:WssX509V3Token10/>
                                                                                                </wsp:Policy>
                                                                                        </sp:X509Token>
                                                                                </wsp:Policy>
                                                                        </sp:InitiatorToken>
                                                                        <sp:RecipientToken>
                                                                            <wsp:Policy>
                                                                                    <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Never">
                                                                                            <wsp:Policy>
                                                                                                    <sp:WssX509V3Token10/>
                                                                                                        <sp:RequireIssuerSerialReference/>
                                                                                                </wsp:Policy>
                                                                                        </sp:X509Token>
                                                                                </wsp:Policy>
                                                                        </sp:RecipientToken>
                                                                        <sp:Layout>
                                                                            <wsp:Policy>
                                                                                    <sp:Strict/>
                                                                                </wsp:Policy>
                                                                        </sp:Layout>
                                                                        <sp:IncludeTimestamp/>
                                                                        <sp:OnlySignEntireHeadersAndBody/>
                                                                        <sp:AlgorithmSuite>
                                                                            <wsp:Policy>
                                                                                    <sp:Basic128/>
                                                                                </wsp:Policy>
                                                                        </sp:AlgorithmSuite>
                                                                </wsp:Policy>
                                                        </sp:AsymmetricBinding>
                                                <sp:Wss10>
                                                    <wsp:Policy>
                                                            <sp:MustSupportRefIssuerSerial/>
                                                        </wsp:Policy>
                                                </sp:Wss10>
                                                <sp:EncryptedParts>
                                                    <sp:Body/>
                                                </sp:EncryptedParts>
                                                <sp:SignedParts>
                                                    <sp:Body/>
                                                    <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                                                    <sp:Header Name="AckRequested" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                                                    <sp:Header Name="SequenceAcknowledgement" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                                                    <sp:Header Name="Sequence" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                                                    <sp:Header Name="CreateSequence" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                                                </sp:SignedParts>
                                            </wsp:Policy>
                                        </sp:BootstrapPolicy>
                                    </wsp:Policy>
                                </sp:SecureConversationToken>
                            </wsp:Policy>
                        </sp:ProtectionToken>
                        <sp:Layout>
                            <wsp:Policy>
                                <sp:Strict/>
                            </wsp:Policy>
                        </sp:Layout>
                        <sp:AlgorithmSuite>
                            <wsp:Policy>
                                <sp:Basic128/>
                            </wsp:Policy>
                        </sp:AlgorithmSuite>
                        <sp:IncludeTimestamp/>
                        <sp:OnlySignEntireHeadersAndBody/>
                    </wsp:Policy>
                </sp:SymmetricBinding>
                <sp:Wss11>
                    <wsp:Policy>
                        <sp:MustSupportRefIssuerSerial/>
                        <sp:MustSupportRefThumbprint/>
                        <sp:MustSupportRefEncryptedKey/>
                    </wsp:Policy>
                </sp:Wss11>
                <sp:Trust13>
                    <wsp:Policy>
                        <sp:RequireClientEntropy/>
                        <sp:RequireServerEntropy/>
                        <sp:MustSupportIssuedTokens/>
                    </wsp:Policy>
                </sp:Trust13>
                <sc:KeyStore wspp:visibility="private" location="C:\Users\AJ\AppData\Roaming\NetBeans\7.3\config\GF3\domain1\config\keystore.jks" type="JKS" storepass="changeit" alias="xws-security-server"/>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsp:Policy wsu:Id="soap_workingPortBinding_hello_Input_Policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:EncryptedParts>
                    <sp:Body/>
                </sp:EncryptedParts>
                <sp:SignedParts>
                    <sp:Body/>
                    <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="AckRequested" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                    <sp:Header Name="SequenceAcknowledgement" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                    <sp:Header Name="Sequence" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                    <sp:Header Name="CreateSequence" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                </sp:SignedParts>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsp:Policy wsu:Id="soap_workingPortBinding_hello_Output_Policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <sp:EncryptedParts>
                    <sp:Body/>
                </sp:EncryptedParts>
                <sp:SignedParts>
                    <sp:Body/>
                    <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/>
                    <sp:Header Name="AckRequested" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                    <sp:Header Name="SequenceAcknowledgement" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                    <sp:Header Name="Sequence" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                    <sp:Header Name="CreateSequence" Namespace="http://docs.oasis-open.org/ws-rx/wsrm/200702"/>
                </sp:SignedParts>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
</definitions>

Here:

  • The Above code is basically xml configuration for our web service.
  • We define the input and output messages for many operations that we’ll define in the next listing.

Listing 2 soap_working.java:

package soappackage;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(serviceName = "soap_working")
public class soap_working {
    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "conversion_from_pounds_to_usd")
    public String conversion_from_pounds_to_usd(@WebParam(name = "pounds") double pounds) {
        //TODO write your implementation code here:
        double usdo=1.0;
        double bpound=0.64;//get value in pounds from user
        pounds=usdo*bpound;
        String conpou=null;
        conpou=String.valueOf(pounds);
        return conpou;
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "conversion_from_usd_to_pounds")
    public String conversion_from_usd_to_pounds(@WebParam(name = "usd") double usd) {
        //TODO write your implementation code here:
        double bpound=0.64;        
        double usdo=1.0;//get value in usd from user
        usd=bpound/usdo;
        String uus=String.valueOf(usd);
        return uus;
    }
}

In the above code:

  • We use @WebService(serviceName = "soap_working") to tell that below class is representing a web service. The service name would be soap_working.
  • Now we start defining logic on what this webservice does. Like one of the functionality is conversion from pound to usd.
  • @WebMethod(operationName = "conversion_from_pounds_to_usd"), In this we are defining a web service method and this operation will be called conversion_from_pounds_to_usd in term of wsdl.
  • Inside the webmethod we define the logic just like we do within any normal java class.

After completing this article, I hope you are comfortable with SOAP. Soap is basically for very complex services. For generating wsdl you can always make use of editors like Netbeans.

Hope you liked it. See you next time.

See also:



My main area of specialization is Java and J2EE. I have worked on many international projects like Recorders,Websites,Crawlers etc.Also i am an Oracle Certified java professional as well as DB2 certified

What did you think of this post?
Services
Know how to keep MrBool Online
SUPPORT US
SUPPORT US
With your help, we can keep providing free content and helping you to be a better professional
support us
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually � in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits � in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login