-eclipse开发工具
里面有自带Web Services Explorer浏览器
在javaEE 下点击右上角wsdlpage 即可
服务端代码
package com.bdqn.ws;import javax.jws.WebMethod;import javax.jws.WebService;@WebServicepublic interface IholloTest { ??????@WebMethod ????String say(String str);}
package com.bdqn.ws;import javax.jws.WebService;@WebServicepublic class IHolleTest implements IholloTest{ ???@Override ???public String say(String str) { ???????System.out.println("http://localhost:8989/FirstWS/adress"+str); ???????return str; ???} ?????}
package com.bdqn.ws;import javax.xml.ws.Endpoint;public class Publishs { ???public static void main(String[] args) { ???????String url="http://localhost:8989/FirstWS/adress" ; ????????Endpoint.publish(url,new IHolleTest()); ???????????????????}}
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.bdqn.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.bdqn.com/" name="IHolleTestService"><types><xsd:schema><xsd:import namespace="http://ws.bdqn.com/" schemaLocation="http://localhost:8989/FirstWS/adress?xsd=1"/></xsd:schema></types><message name="say"><part name="parameters" element="tns:say"/></message><message name="sayResponse"><part name="parameters" element="tns:sayResponse"/></message><portType name="IHolleTest"><operation name="say"><input wsam:Action="http://ws.bdqn.com/IHolleTest/sayRequest" message="tns:say"/><output wsam:Action="http://ws.bdqn.com/IHolleTest/sayResponse" message="tns:sayResponse"/></operation></portType><binding name="IHolleTestPortBinding" type="tns:IHolleTest"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="say"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output></operation></binding><service name="IHolleTestService"><port name="IHolleTestPort" binding="tns:IHolleTestPortBinding"><soap:address location="http://localhost:8989/FirstWS/adress"/></port></service></definitions>
在cmd 窗口用jdk 指令 生成客户端的代码
注意(这里发布的url 是自己本机的IP)
这里的wsdl文件 可以是 网络的http://localhost:8989/FirstWS/adress?wsdl 也可以是项目中本地wsdl文件(是在网络文件copy)
执行完指令后生成com.bdqn.ws包下所有的类,--这里的包名是来源于服务端的包名
package com.bdqn.client;import com.bdqn.ws.IHolleTest;import com.bdqn.ws.IHolleTestService;public class Clientws { public static void main(String[] args) { ????IHolleTestService holle=new IHolleTestService(); ?????IHolleTest test=holle.getIHolleTestPort(); ?????System.out.println(test.getClass()); ?????String say=test.say("xiaoli "); ?????System.out.println(say);}}
启动服务后客户端方可调用服务端的代码。
web service ??用JDK开发 版本在1.6以上
原文地址:http://www.cnblogs.com/ou-pc/p/7497719.html