首页

java 调用Webservice 示例代码

java

2020-8-10

jdk1.6实现的发布webservice,绝对好用

package myjava;

import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class CallService {
	public static void main(String[] args) {
		 // 创建访问wsdl服务地址的url 
	    try { 
	        URL url = new URL("http://localhost:8081/testWS?wsdl"); 
	        // 通过Qname指明服务的具体信息 
	        QName sname = new QName("http://myjava/", 
	                "HelloService"); 
	        // 创建服务 
	        Service service = Service.create(url, sname); 
	        // 实现接口 
	        Helloin ms = service.getPort(Helloin.class); 
	        System.out.println(ms.say()); 
	    } catch (Exception e) { 
	        e.printStackTrace(); 
	    }  
	}
}

资源下载此资源下载价格为2D币(VIP免费),请先
资源文件列表
testWS/.classpath , 529
testWS/.mymetadata , 291
testWS/.project , 1749
testWS/.settings/.jsdtscope , 500
testWS/.settings/com.genuitec.eclipse.ws.prefs , 109
testWS/.settings/org.eclipse.jdt.core.prefs , 395
testWS/.settings/org.eclipse.wst.common.component , 456
testWS/.settings/org.eclipse.wst.common.project.facet.core.xml , 252
testWS/.settings/org.eclipse.wst.jsdt.ui.superType.container , 49
testWS/.settings/org.eclipse.wst.jsdt.ui.superType.name , 6
testWS/WebRoot/META-INF/MANIFEST.MF , 36
testWS/WebRoot/WEB-INF/classes/myjava/CallService.class , 1325
testWS/WebRoot/WEB-INF/classes/myjava/Hello.class , 479
testWS/WebRoot/WEB-INF/classes/myjava/Helloin.class , 204
testWS/WebRoot/WEB-INF/classes/myjava/mymain.class , 560
testWS/WebRoot/WEB-INF/web.xml , 404
testWS/WebRoot/index.jsp , 834
testWS/src/myjava/CallService.java , 734
testWS/src/myjava/Hello.java , 201
testWS/src/myjava/Helloin.java , 121
testWS/src/myjava/mymain.java , 192
没有账号? 忘记密码?

社交账号快速登录