What is a WebService? A small example of a webService Learn more about this
Enter the topic below:
Java web project ( spring Integrated webservice in project To open the interface to the outside world:
Get ready:
Using cxf with good compatibility with spring
The jar download address for cxf: http://cxf.apache.org/download.html
Choose zip format to download, jar in lib directory after decompression
The minimum jar s required are as follows:
cxf-2.3.3.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-jaxws_2.2_spec-1.0.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.3.jar
jaxb-api-2.2.1.jar
jaxb-impl-2.2.1.1.jar
neethi-2.0.4.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.7.jar
wstx-asl-3.2.9.jar
One: Create a web service server
1) Create a service interface
2) Is an interface implementation class
3) Create a spring configuration file to add service classes to the container
webservice.xml
Add a webservice.xml configuration file to the web.xml
4) Add cxf servlet to web.xml
The webservice server is now created.
Access: http://localhost:8080/test/webservice/HelloWorld?wsdl in a browser (test is the project name).If something similar to
<wsdl:definitions xmlns:ns1="http://service.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.service.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloWorldImplService" targetNamespace="http://impl.service.com/"> . . . .
Configuration was successful.
Following are a few runtime error resolution tips
1:webservice.xml prompts cxf.xml, cxf-servlet.xml is not found, the path I wrote above is classpath*:META-INF/cxf/cxf.xml, where classpath is followed by a'*'symbol, unsigned means that only the cxf.xml file is found under the class path, plus sign means that not only the XML file is found under the class path, but also under the class pathFind the XML file in the jar package.So if we don't have a configuration file such as cxf.xml under the project class path, we have to append * to the classpath so that the spring container will find it in the jar package we've added.
2: If you do not write a mapping path as /* when using a cxf servlet, otherwise you will not be able to access the project home page, you can write as a request path for a cxf servlet as / webservice/* or a path that has not been used in other projects.
2: Create a web service client
Clients can be used in the same project as servers test Or create a new one Java Project for testing.
When creating a new Java project test, assume that the corresponding jar package, like the server, uses spring and assumes the spring jar package.
I'm creating a new project here and still using spring to test
1) First, create a service interface that is the same as the server side. (You can omit this step if the client and server sides are in the same project.)
2) Create spring-client.xml,
3) Test Class
- package com.test;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.service.IHelloWorld;
- public class Test {
- public static void main(String[] args) {
- ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-client.xml");
- IHelloWorld client = (IHelloWorld) ctx.getBean("client");
- String result = client.sayHello; (Hello!)
- System.out.println(result);
- }
- }
Show after successful run
Hello: Hello!
Other and webservice Related Links 5 Minute use Spring4 Build one REST WebService http://www.cnblogs.com/tzyy/p/4837701.html Java WebService Simple small example http://blog.csdn.net/mixika99/article/details/51647972 MyEclipse10.7.1+JDK 1.6.0_22 Create [ Web Service Project] http://www.iteye.com/topic/1135747 Webservice Working principle and examples http://blog.csdn.net/yangwenxue_admin/article/details/51059125 java Realization WebService And different ways of calling http://www.cnblogs.com/siqi/archive/2013/12/15/3475222.html Java call WebService The interface implements the function of sending SMS verification codes. java Mobile phone verification code, WebService Interface Call http://blog.csdn.net/sxdtzhaoxinguo/article/details/34437591 W3School Web Services Course http://www.w3school.com.cn/webservices/
From: http://blog.csdn.net/mixika99/article/details/54407667