webservice xfire 客户端调用「建议收藏」

webservice xfire 客户端调用「建议收藏」[code="java"]现在我们来看xfire的客户端调用,有两种方式:一、通过服务端提供的接口类进行调用。Java代码packagecom.wujianjun.xfire.client;importjava.net.MalformedURLException;importjava.util.List;imp…

大家好,欢迎来到IT知识分享网。


现在我们来看xfire的客户端调用,有两种方式:

一、通过服务端提供的接口类进行调用。

Java代码
package com.wujianjun.xfire.client;

import java.net.MalformedURLException;
import java.util.List;

import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import com.wujianjun.xfire.domain.Person;
import com.wujianjun.xfire.spring.IPersonService;

public class PojoInvokeClient {

public static void main(String[] args) {
Service serviceModel = new ObjectServiceFactory().create(IPersonService.class);

XFire xfire = XFireFactory.newInstance().getXFire();
XFireProxyFactory factory = new XFireProxyFactory(xfire);
String serviceUrl = "http://127.0.0.1:8080/xfire/services/PersonService";

IPersonService client = null;
try {
client = (IPersonService) factory.create(serviceModel, serviceUrl);
} catch (MalformedURLException e) {
System.out.println("Client call webservice has exception: "+ e.toString());
}

String result1 =client.sayHello("张三");

}
}

二、直接通过url调用, 不用客户端提供接口类

Java代码
package com.wujianjun.xfire.client;

import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.client.Client;

public class UrlInvokeClient {

public static void main(String[] args) {
Client client = null;
try {
client = new Client(new URL("http://127.0.0.1:8080/xfire/PersonService.ws?wsdl"));
Object[] result1 = client.invoke("sayHello", new Object[] {"张三"});
System.out.println(result1[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/25672.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信