Java Login

About javalogin.com

Hello guys,
javalogin.com is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.


     << Previous
Next >>     


SOAP Web Service End Point

Endpoint is the URL where your service can be accessed by a client application. Web services expose one or more endpoints to which messages can be sent. A web service endpoint is an entity, processor, or resource that can be referenced and to which web services messages can be addressed. Endpoint references convey the information needed to address a web service endpoint. Clients need to know this information before they can access a service.


An endpoint can be thought of as a physical manifestation of a service. It combines a binding, which specifies the physical representation of the logical data used by a service, and a set of networking details that define the physical connection details used to make the service contactable by other endpoints. Endpoints are defined in a contract using a combination of the WSDL service element and the WSDL port element. The service element is a collection of related port elements. The port elements define the actual endpoints. The WSDL service element has a single attribute, name, that specifies a unique name. The service element is used as the parent element of a collection of related port elements. WSDL makes no specification about how the port elements are related. You can associate the port elements in any manner you see fit.


@WebService

The following is all that is required. No external xml files are needed. This class placed in a jar or war and deployed into a compliant Java EE server like TomEE is enough to have the Calculator class discovered and deployed and the webservice online.

import javax.ejb.Stateless;
import javax.jws.WebService;

@Stateless @WebService(
portName = "CalculatorPort",
serviceName = "CalculatorService",
targetNamespace = "http://superbiz.org/wsdl",
endpointInterface = "org.superbiz.calculator.ws.CalculatorWs")
public class Calculator implements CalculatorWs {

public int sum(int add1, int add2) {
return(add1 + add2;)
}

public int multiply(int mul1, int mul2) {
return(mul1 * mul2;)
}

}

@WebService Endpoint Interface

Having an endpoint interface is not required, but it can make testing and using the web service from other Java clients far easier.

import javax.jws.WebService;

@Stateless @WebService(targetNamespace = "http://superbiz.org/wsdl")
public interface CalculatorWs {

public int sum(int add1, int add2) ;

public int multiply(int mul1, int mul2) ;

}

Calculator WSDL

The wsdl for our service is autmatically created for us and available at http://127.0.0.1:4204/Calculator?wsdl. In TomEE or Tomcat this would be at http://127.0.0.1:8080/simple-webservice/Calculator?wsdl

<?xml version="1.0" encoding= ""UTF-8">
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
name="CalculatorService"
targetNamespace="http://superbiz.org/wsdl"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://superbiz.org/wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"

<wsdl:types>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="unqualified" targetNamespace="http://superbiz.org/wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://superbiz.org/wsdl">

<xsd:element name="multiply"type="tns:multiply"/>
<xsd:complexType name="multiply">
<xsd:sequence>
<xsd:element name="arg0" type="xsd:int">
<xsd:element name="arg1" type="xsd:int">
</xsd:sequence>
</xsd:complexType>
<xsd:element name="multiplyResponse"type="tns:multiplyResponse"/>
<xsd:complexType name="multiplyResponse">
<xsd:sequence>
<xsd:element name="return" type="xsd:int">
</xsd:sequence>
</xsd:complexType>
<xsd:element name="sum"type="tns:sum"/>
<xsd:complexType name="sum">
<xsd:sequence>
<xsd:element name="arg0" type="xsd:int">
<xsd:element name="arg1" type="xsd:int">
</xsd:sequence>
</xsd:complexType>
<xsd:element name="sumResponse"type="tns:sumResponse"/>
<xsd:complexType name="sumResponse">
<xsd:sequence>
<xsd:element name="return" type="xsd:int">
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>

<wsdl:message name="multiplyResponse">
<wsdl:part element="tns:multiplyResponse" name="parameters">
</wsdl:message>
<wsdl:message name="sumResponse">
<wsdl:part element="tns:sumResponse" name="parameters">
</wsdl:message>
<wsdl:message name="sum">
<wsdl:part element="tns:sum" name="parameters">
</wsdl:message>
<wsdl:message name="multiply">
<wsdl:part element="tns:multiply" name="parameters">
</wsdl:message>

<wsdl:portType name="CalculatorWs">
<wsdl:operation name="multiply">
<wsdl:input message="tns:multiply" name="multiply">
<wsdl:output message="tns:multiplyResponse"
name="multiplyResponse">
</wsdl:operation>
<wsdl:operation name="sum">
<wsdl:input message="tns:sum" name="sum">
<wsdl:output message="tns:sumResponse" name="sumResponse">
</wsdl:operation>
</wsdl:portType name="CalculatorWs">

<wsdl:binding name="CalculatorServiceSoapBinding"
type="tns:CalculatorWs">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http">
<wsdl:operation name="multiply">
<soap:operation soapAction=""style="document">
<wsdl:input name="multiply">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="multiplyResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sum">
<soap:operation soapAction=""style="document">
<wsdl:input name="sum">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sumResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CalculatorService">
<wsdl:port binding="tns:CalculatorServiceSoapBinding"
name="CalculatorPort">
<soap:address location="http://127.0.0.1:4204/Calculator?wsdl"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>




Each endpoint supported by your WCF service application must be defined in the web.config settings for the application. The protocol and address of each endpoint must be unique. For example, two endpoints can have the same address if they specify different protocols in their respective bindings. However, if two endpoints use the same protocol, they must specify different addresses. Use a unique endpoint address for every endpoint so that these addresses are not dependent on the binding protocol. Specify an endpoint address that is relative to the base address configured by the Service Application Framework.


By default, a web service application has one HTTP endpoint. If this is the configuration you want for your service application, no changes are required. If you want to use a different protocol or if you want to support multiple endpoints, you must explicitly define all of the endpoints your service application will support.


     << Previous
Next >>