Java and WCF interaction (2): the WCF client calls Java web service

Source: Internet
Author: User
Tags webservice annotation

In the previous article "Java and WCF interaction (I): using a Java client to call the WCF Service", I introduced my own miserable experiences in using axis2 to generate a java client. Some people asked what protocol they used. After preliminary verification, they found that only wsHttpBinding was feasible, but NetTcpBinding was not feasible. The specific reason is to be found. I went back to test the WCF client to call Java Web Service last night and announced the process as follows:

Step 1: create a local java environment, build web Service Code, and publish web service

1. Set the Java environment:

JDK 6/J2SE1.6 or above. required !! The reason will be explained later in the invitation month.

Eclipse 3.6

Axis2_Codegen_Wizard_1.4.1 plug-in. For configuration, see Java and WCF interaction (1): Java client calls the WCF Service.

Assume that all the above environments are OK.

2. Services server applications

Create a new java project named assumerviceforwcfclient in Eclipse,

Select a Runtime Library

Create a package under src,

Create a new class HelloTimeForWCF under the package. The Code is as follows:

Note: Use of @ WebService. This is called Annotation or Metadata, which is used by the Web Services Metadata Specification (Web Services Metadata Specification) introduced in Java SE 5. Before applying Annotation to classes and methods, developers Define classes and methods to indicate to the runtime engine how to enable classes and methods as Web Services and Web Services operations. Java SE 6 comes with such an engine. @ WebService Annotation mark the SayHello class as implementing a Web service to generate deployable Web Services. This specific Annotation is a wsdl ing Annotation, And the Java source code is associated with the WSDL element indicating Web Services.

Next, it's time for Ant tools to come in handy,

Create a new build. xml file in the root path of the project.

Run the file as "Ant Build:

You should receive the following information on the console:

The preceding information indicates that ant is successfully created! In this case, refresh the project view and the expected result. The yellow part is the newly generated content:

Add a new primary class in the package. Does it feel a bit like the Host engine in WCF? In fact, this is the role.

The content is as follows:

Running a program is like running a Host in WCF:


So far, the Java web end has been deployed.

 


Step 2: create a local WCF client and call the web service generated in step 1

Create a common console project named WCFClientFromJava and use the SvcUtil command as shown in. (Svcutil.exe, ServiceModel metadata utility is used to generate service model code based on the metadata document, and generates metadata documents based on the service model code. ServiceModel metadata utility can be found in the installation location of the Windows SDK, generally C: Program FilesMicrosoft SDKsWindowsv6.0Bin)

After the file is generated, it is included in the project. The project structure is as follows:

The generated app. config file is as follows:

Add the following method to the program. cs file:

So far, the WCF client has successfully called Java Web service!

 

Related Article

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.