How to reference and find Web services in J2EE components

Source: Internet
Author: User
This article will discuss how to reference Web services in J2EE components and use JNDI to find Web services. In the content organization, first publish an EJB2.1 stateless session Bean as a Web service, then develop a JSP-based Web service client, and finally introduce how to reference the Web service during JSP deployment, we also discuss how to use JNDI to find and call Web services.
Before reading this article, you need the following knowledge and tools:
J2EE1.4 SDK, which will be used initially;
Master basic JAX-RPC Web service development skills;
Understand the basic knowledge of JNDI and be able to use it for simple programming;
General Java programming knowledge.
Web service client we know that JAX-RPC Web service client has the following types:
Based on Stub;
Based on dynamic proxy;
Based on the Dynamic Call Interface (DII ).
In fact, the above three clients use the Service interface as their creation factory. The Service interface defines the following methods:
Some methods in routine 1 Service interface
Call createCall ();
Call createCall (QName portName,
String operationName );
Remote getPort (QName portName,
Class serviceEndpointInterface );
Remote getPort (Class serviceEndpointInterface );
It can be seen that the Call object and Remote object can be created through the Service interface, and the Call or Remote object is exactly what the Web Service needs to Call. By using the Service interface, we can call the Web Service client in the following ways:
Routine 2 call Web services on the client
// Create a ServiceFactory object.
ServiceFactory serviceFactory
= ServiceFactory. newInstance ();
// Use ServiceFactory
Object to create a Service object that calls the Web Service.
Service service =
ServiceFactory. createService
(TaxWsdlUrl,
New QName (nameSpaceUri,
ServiceName ));
// Obtain the service endpoint instance.
TaxService myProxy =
(TaxService) service. getPort
(New QName (nameSpaceUri,
PortName ),
TaxService. class );
// Call the Web service.
Double result = myProxy. calculateTax (5000 );
It can be seen that when creating a Service instance, you need to use the specified WSDL file location, a valid namespace consisting of the Service name and namespace URI, which makes it complex to create this instance. The JAX-RPC specification recommends using JNDI to find service interfaces. Through JNDI, it is as simple as calling EJB to call Web services. You can obtain the Web service interface in two steps:
Initialize a namespace context;
Search for Web services in this context.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.