Web Services SOAP (WSDL) MockService by SoapUI Tutorial



Why Mock-service? Advantage/Disadvantage, refer from http://www.soapui.org/

Let's discussed more about how to moking SOAP by SoapUI tool:

Click me for WSDL Details

Save this wsdl in your local drive. e.g: c:\wsdl\GreetingWebService_1.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<!--Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.--><!--Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.--><definitions targetNamespace="http://webservicejaxws.vinod.com/" name="GreetingWebServiceImplService" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservicejaxws.vinod.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://webservicejaxws.vinod.com/" schemaLocation="GreetingWebService.xsd"/>
    </xsd:schema>
  </types>
  <message name="sayWelcome">
    <part name="parameters" element="tns:sayWelcome"/>
  </message>
  <message name="sayWelcomeResponse">
    <part name="parameters" element="tns:sayWelcomeResponse"/>
  </message>
  <portType name="GreetingWebService">
    <operation name="sayWelcome">
      <input wsam:Action="http://webservicejaxws.vinod.com/GreetingWebService/sayWelcomeRequest" message="tns:sayWelcome"/>
      <output wsam:Action="http://webservicejaxws.vinod.com/GreetingWebService/sayWelcomeResponse" message="tns:sayWelcomeResponse"/>
    </operation>
  </portType>
  <binding name="GreetingWebServiceImplPortBinding" type="tns:GreetingWebService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="sayWelcome">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
  <service name="GreetingWebServiceImplService">
    <port name="GreetingWebServiceImplPort" binding="tns:GreetingWebServiceImplPortBinding">
      <soap:address location="http://localhost:8080/jaxwsprj/GreetingWebService"/>
    </port>
  </service>
</definitions>

c:\wsdl\GreetingWebService.xsd

<?xml version="1.0" encoding="UTF-8"?>
<!--Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b.--><xs:schema version="1.0" targetNamespace="http://webservicejaxws.vinod.com/" xmlns:tns="http://webservicejaxws.vinod.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="sayWelcome" type="tns:sayWelcome"/>
  <xs:element name="sayWelcomeResponse" type="tns:sayWelcomeResponse"/>
  <xs:complexType name="sayWelcome">
    <xs:sequence>
      <xs:element name="sName" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="sayWelcomeResponse">
    <xs:sequence>
      <xs:element name="return" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Note: Just verify your proxy setting as none.  File > Preferences > Proxy Settings > None.

Open the SoapUI tool Click me for Details
Click on the Projects
File > New SOAP Project
Project Name: JAXWS-SOAP-MockingService
Click on the Browse Button
Select the saved wsdl file from c:\JAXWSWSDLSample.wsdl
or enter the URL http://localhost:8080/jaxwsprj/GreetingWebService
Default Create Request as selected and leave other two as deselected
Click Ok.

Dir structure look like:

Projects
- JAXWS-SOAP-MockingService
   - GreetingWebServiceImplPortBinding
      - sayWelcome
        Request 1

Note: Mack sure port 8080 not at all use for any other purpose

Generate Mock Service:

Right Click on GreetingWebServiceImplPortBinding

















Click on the Ok.
Ok.












Bubble click on the Response 1 and change the
value to
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservicejaxws.vinod.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:sayWelcomeResponse>
         <!--Optional:-->
         <return>Hello</return>
      </web:sayWelcomeResponse>
   </soapenv:Body>
</soapenv:Envelope>

Right click on the GreetingWebServiceImplPortBinding MockService
Start Minimized

Bubble click on the Request 1 and change the http://localhsot:8080/mockGreetingWebServiceImplPortBinding

Click on the Green Arrow Button.

OutPut:

Response will come from Mock Service:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webservicejaxws.vinod.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:sayWelcomeResponse>
         <!--Optional:-->
         <return>Hello</return>
      </web:sayWelcomeResponse>
   </soapenv:Body>

</soapenv:Envelope>



1 comment:

  1. Good post.....learned it for interview preparation.....nicely explained...soap mocking.

    ReplyDelete