A Smple JAX-WS Service in the CXF Distribution
2013-09-28 22:36
302 查看
Writing your Service 1
Wirting your service interface at first 1
Implement your service inerface secondly 1
Writing your service at thirdly 2
Testing your service at last 2
Accessing your service by client 2
2.做必要的注释
import javax.jws.WebService;
import javax.xml.ws.BindingType;
@WebService
@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING)
public interface HelloWorld{
String SayHello_TO_Client();
//Add other operations your need
}
@WebService(endpointInterface = "demo.hw.server.HelloWorld",
serviceName = "HelloWorld") //注解命名空间和服务名称
public class HelloWorldImpl implements HelloWorld {
@Override
public String SayHello_TO_Client() {
String str =“say hello to client”
return str;
}
//Add other operations implement your add in interface
}
public class Service {
public static void main(String[] args) throws Exception {
HelloWorldImpl helloworldImpl = new HelloWorldImpl();
JaxWsServerFactoryBean factory2 = new JaxWsServerFactoryBean(); factory2.setServiceClass(HelloWorld.class);
factory2.setAddress("http://localhost:9000/helloWorld?wsdl");
//服务地址构成 http://IP:端口号/接口名称(可选)?wsdl
factory2.setServiceBean(helloworldImpl);
factory2.create();
}
SoapObject soapObject = new SoapObject("http://unknown.namespace/", "SayHello_TO_Client()");
//soapObject.addProperty("byProvinceName", byProvinceName); 如果需要传入参数则通过此方法
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //版本
envelope.bodyOut = soapObject;
envelope.dotNet = false;
envelope.setOutputSoapObject(soapObject);
try {
HttpTransportSE trans = new HttpTransportSE("http://localhost:9000/helloWorld?wsdl");
trans.debug = false; // 调试功能
trans.call(null, envelope);
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (XmlPullParserException e) {
e.printStackTrace();
return null;
}
str = ((SoapObject) envelope.bodyIn).getProperty("return").toString();
return str;
}
Wirting your service interface at first 1
Implement your service inerface secondly 1
Writing your service at thirdly 2
Testing your service at last 2
Accessing your service by client 2
Writing your Service
Wirting your service interface at first
1.申明服务提供的接口函数,数量不唯一。2.做必要的注释
import javax.jws.WebService;
import javax.xml.ws.BindingType;
@WebService
@BindingType(value = javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING)
public interface HelloWorld{
String SayHello_TO_Client();
//Add other operations your need
}
Implement your service inerface secondly
1.实现服务提供的接口函数。@WebService(endpointInterface = "demo.hw.server.HelloWorld",
serviceName = "HelloWorld") //注解命名空间和服务名称
public class HelloWorldImpl implements HelloWorld {
@Override
public String SayHello_TO_Client() {
String str =“say hello to client”
return str;
}
//Add other operations implement your add in interface
}
Writing your service at thirdly
Method-1:public class Service {
public static void main(String[] args) throws Exception {
HelloWorldImpl helloworldImpl = new HelloWorldImpl();
JaxWsServerFactoryBean factory2 = new JaxWsServerFactoryBean(); factory2.setServiceClass(HelloWorld.class);
factory2.setAddress("http://localhost:9000/helloWorld?wsdl");
//服务地址构成 http://IP:端口号/接口名称(可选)?wsdl
factory2.setServiceBean(helloworldImpl);
factory2.create();
}
Testing your service at last
Pointing your browser at http://localhost:9000/helloWorld?wsdl will display the wsdl for this serviceAccessing your service by client
public static String GetServerStr() {SoapObject soapObject = new SoapObject("http://unknown.namespace/", "SayHello_TO_Client()");
//soapObject.addProperty("byProvinceName", byProvinceName); 如果需要传入参数则通过此方法
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //版本
envelope.bodyOut = soapObject;
envelope.dotNet = false;
envelope.setOutputSoapObject(soapObject);
try {
HttpTransportSE trans = new HttpTransportSE("http://localhost:9000/helloWorld?wsdl");
trans.debug = false; // 调试功能
trans.call(null, envelope);
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (XmlPullParserException e) {
e.printStackTrace();
return null;
}
str = ((SoapObject) envelope.bodyIn).getProperty("return").toString();
return str;
}
相关文章推荐
- JAX-WS 2.2 API is required, but an older version was found in the JDK.
- jaxws soap webservice 使用apache cxf tool ——wsdl2java
- WebService CXF学习(进阶篇2):JAX-WS讲解
- CXF 发布Web Service - JaxWsWebServicePublisherBeanPostProcessor
- Apache Axis2, CXF and Sun JAX-WS RI in comparison
- Adding SOAP headers in the JAX-WS
- javax.xml.ws.WebServiceException: No Content-type in the header!
- 简单的Jax-WS WebService实现-cxf
- Agile PLM --- JAX-WS 2.2 API is required, but an older version was found in the JDK
- javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy, either Service in
- Web Service Jaxws注解、CXF注解和发布
- jax-ws之webservice security(安全)教程第三天
- Cannot expand the COM+ list in the Component Services UI due to MSDTC service permission issue
- (JAX-WS) in Java EE 5快速上手
- REST service example using CXF 2.2, JAX-RS 1.0, JAXB and Spring
- CXF之jaxws:endpoint对spring bean的引用
- Spring Boot用Cxf的jax-ws开发WebService
- 利用jaxws创建service 和 client 简单方法
- Running a Service in the Foreground
- JAX-WS WebService