Http://blog.csdn.net/downmoon/article/details/5836933
In the previous article 《
Java and WCF interaction (1): Java client calls the WCF Service
This section describes how to use axis2 to generate a Java client. Some people asked what protocols they used. After preliminary verification, they found that only wshttpbinding was feasible, while
Nettcpbinding is unavailable. The specific cause is to be queried. I went back to test the WCF client to call Java Web service last night and announced the process as follows:
In fact, this does not need to be a web service, but the original published classic Web Service Image (
Http://soapinterop.java.sun.com/round2.base? WSD
L. As a result, a local web service was rewritten in the invitation month for demonstration.
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 the configuration, see the preceding section.
《
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:@ WebService
Of
. This is called annotation or metadata, and the Web services metadata specification (Web Services) introduced in Java SE 5
Metadata specification. Developers apply annotation to classes and methods.
Previously, classes and methods were defined to indicate to the runtime engine how to enable the classes and their methods as Web Services and web services operations. Java SE 6
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. (Note: This section is from the IBM official website, https://www6.software.ibm.com/developerworks/cn/education/webservices/ws-eclipse-javase1/section3.html
)
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:
You can use an internal browser to browse this address:Http: // localhost: 8080/assumerviceforwcfclient? WSDL
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 ,,
Run the svcutil command: (svcutil.exe, servicemodel
The metadata utility is used to generate the service model code based on the metadata document and the metadata document based on the service model code. The servicemodel metadata utility can be found in
Windows SDK installation location, usually C:/program files/Microsoft
Sdks/Windows/v6.0/bin)
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!
Summary: this is a simple demo. The main technical points are:
1. For the use of @ WebService, see
Http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/
2. For the use of svcutil, see msdn:
Http://msdn.microsoft.com/zh-cn/library/aa347733%28VS.90%29.aspx
Reference:
Use eclipse and Java SE 6 to create an independent Web Services application, Part 1:
Web services server applications
Https://www6.software.ibm.com/developerworks/cn/education/webservices/ws-eclipse-javase1/section3.html
Introducing JAX-WS 2.0 with the Java SE 6 platform, part 1
Http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/
Invitation month Note: The copyright of this article is jointly owned by the invitation month and csdn. For more information, see the source.
Helping others is the same as self-help!
3w@live.cn