Java 调用webservice接口测试
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java 调用webservice接口测试,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3624字,纯文字阅读大概需要6分钟。
内容图文
Java环境:Eclipse4.4.1 Jdk1.6 Cxf2.71、WebService 服务端文件:
文件组成很简单:webservice接口ICc 和 接口类实现CcImpl
ICc 接口代码如下:
package com.yp.webservice; import javax.jws.WebMethod; import javax.jws.WebService; /** * * @author yakcy * @version v1.0.0 * @date 2014-11-7 * */ @WebService(name="ICc",targetNamespace="http://test.com") public interface ICc { @WebMethod void showMessages(); }CcImpl 接口实现代码如下:
package com.yp.webservice; import javax.jws.WebMethod; import javax.jws.WebService; /** * * @author yakcy * @version v1.0.0 * @date 2014-11-7 * */ @WebService(name = "ICc", targetNamespace = "http://test.com", endpointInterface = "com.yp.webservice.ICc") public class CcImpl implements ICc { @WebMethod @Override public void showMessages() { System.out.println("Everthing is OK..."); } }
2、服务端配置:applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- START SNIPPET: beans --> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="Cc" implementor="com.yp.webservice.CcImpl" address="/Cc" /> <bean id="client" class="com.yp.webservice.ICc" factory-bean="clientFactory" factory-method="create" /> <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"> <property name="serviceClass" value="com.yp.webservice.ICc" /> <property name="address" value="http://localhost:8080/ypms/services/Cc" /> </bean> </beans> <!-- END SNIPPET: beans -->
3、webservice客户端(新建一个java 项目,将webservice服务端代码打包成jar导入到客户端项目)文件如下:
webServiceTest代码如下:
public class WebServiceTest { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); ICc client = (ICc) context.getBean("client"); <span style="color:#FF0000;">//如果webservice接口中出现过自定义类,必须将源码添加到客户端中,否则创建client会报找不到</span> client.showMessages(); } } 备注:<span style="color:#FF0000;"><span style="background-color: rgb(255, 255, 255);">客户端的applicationContext.xml内容与服务端一致</span></span>
4、先发布webservice接口,生成WSDl文件(在浏览器中输入:http://localhost:8080/ypms/services/Cc?wsdl,如下所示:
备注以上内容可能不同,只要能看到自己写的方法就可以了
5、运行客户端代码,结果如下:
总结:
这样webservice调用就成功了, 其实客户端可以通过在Eclipse安装Xfire插件,添加WDSL路径自动生成webservice客户端代码,不过遇到个问题很久没解决如下:
问题:关于带參的方法调用导致成意外元素
如果有遇到过解决了的朋友可以分享下。。。
原文:http://blog.csdn.net/cqboy1991/article/details/41727495
内容总结
以上是互联网集市为您收集整理的Java 调用webservice接口测试全部内容,希望文章能够帮你解决Java 调用webservice接口测试所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。