文档详情

CXF笔记.docx

发布:2017-05-14约4.09千字共5页下载文档
文本预览下载声明
1、先下载CXF开发包2、新建一个普通java项目。3、引入包:里面有个jetty,其实这是CXf里面包含的一个小的容器,可以启动。然后写:package com.liu.cxf.ws;importjavax.jws.WebService;@WebServicepublicinterfaceHelloWorld { String sayHi(String name);}package com.liu.cxf.ws.impl;import javax.jws.WebService;import com.liu.cxf.ws.HelloWorld;//每个webService组件需要两个部分:接口、实现类。@WebService(endpointInterface=com.liu.cxf.ws.HelloWorld,serviceName=HelloWorldWS)public class HelloWorldImpl implements HelloWorld{@Overridepublic String sayHi(String name) {// TODO Auto-generated method stubreturn HelloWorld+name;}}主方法,可以运行起来package com.liu.publish;import javax.xml.ws.Endpoint;import com.liu.cxf.ws.HelloWorld;import com.liu.cxf.ws.impl.HelloWorldImpl;public class ServerMain {public static void main(String[] args) {// TODO Auto-generated method stubHelloWorld hw=new HelloWorldImpl();Endpoint.publish(87/HWServer, hw);System.out.println(服务发布成功);}}在浏览器中访问:87/HWServer?wsdl?xml version=1.0 ?-wsdl:definitions name=HelloWorldWStargetNamespace=/ xmlns:ns1=/ xmlns:ns2=/soap/httpxmlns:soap=/wsdl/soap/xmlns:tns=/xmlns:wsdl=/wsdl/xmlns:xsd=/2001/XMLSchemawsdl:importlocation=87/HWServer?wsdl=HelloWorld.wsdl namespace=/ /-wsdl:binding name=HelloWorldWSSoapBinding type=ns1:HelloWorldsoap:bindingstyle=document transport=/soap/http /-wsdl:operation name=sayHisoap:operationsoapAction= style=document /-wsdl:input name=sayHisoap:bodyuse=literal //wsdl:input-wsdl:output name=sayHiResponsesoap:bodyuse=literal //wsdl:output/wsdl:operation/wsdl:binding-wsdl:service name=HelloWorldWS-wsdl:port binding=tns:HelloWorldWSSoapBinding name=HelloWorldImplPortsoap:addresslocation=87/HWServer //wsdl:port/wsdl:service/wsdl:definitions客户端访问部分进到项目的安装目录下用wsdl2java87/HWServer?wsdl实际操作的时候用了:E:\AllWorkspace\MyEclipse 102\CXFStudy1_Client\srcwsdl2java -frontend jaxws2105:8888/HWServer?wsdl这个操作可以生成相應的客戶端java代碼。1任何語言實現了web service,都需要提供、并暴漏wsdl文檔2找到wsdl2java生成類中,一個繼承了service的類,該類的實例可以當成工廠來使用3調用service子類的實例的getxxxPort,返回遠程web service的代理=====================================1、當形參、返回值的類型是string、基本
显示全部
相似文档