分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

web service ??用JDK开发 版本在1.6以上

发布时间:2023-09-06 01:09责任编辑:苏小强关键词:暂无标签

-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()); ???????????????????}}
endpoint 发布
<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>
WSDL 文档

在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);}}
client 客户端

 启动服务后客户端方可调用服务端的代码。

web service ??用JDK开发 版本在1.6以上

原文地址:http://www.cnblogs.com/ou-pc/p/7497719.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved