|
//
包名
package
net.ruixin.webservicedemo;
/**
*
服务实现类的实现
* @author caoxiang
*/
public
class HelloWorldServiceImpl implements IHelloWorldService {
/**
*
返回名称的方法
* @param name
名称
*/
public String sayHello(String name){
return "
您好,"+name;
}
}
|
|
//
包名
package
net.ruixin.webservicedemo;
/**
*
服务接口类的创建
* @author caoxiang
*/
public
interface IHelloWorldService {
/**
*
返回名称的方法
* @param name
名称
* @return
返回值
*/
public String sayHello(String name);
}
|
|
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>HelloWorldService</name>
<serviceClass>
net.ruixin.webservicedemo.IHelloWorldService
</serviceClass>
<implementationClass>
net.ruixin.webservicedemo.HelloWorldServiceImpl
</implementationClass>
<scope>application</scope>
</service>
</beans>
|
|
WebService
的服务名
<name>HelloWorldService</name>
WebService
的服务接口类<serviceClass>net.ruixin.webservicedemo.IHelloWorldService
</serviceClass>
WebService
的服务接口实现类<implementationClass>net.ruixin.webservicedemo.HelloWorldServiceImpl</implementationClass>
WebService
的服务有效范围
<scope>application</scope>
|
|
//
包名
package
net.ruixin.webservicedemo;
import
java.net.MalformedURLException;
import
org.codehaus.xfire.XFireFactory;
import
org.codehaus.xfire.client.XFireProxyFactory;
import
org.codehaus.xfire.service.Service;
import
org.codehaus.xfire.service.binding.ObjectServiceFactory;
/**
*
测试服务类的创建
* @author caoxiang
*/
public
class HelloWorldClient {
/**
*
测试主程序
* @param args
* @throws Exception
*/
public static void main(String args[]) {
//
通过接口类创建Service对象
Service srvcModel = new ObjectServiceFactory()
.create(IHelloWorldService.class);
//
通过XFire的工厂类创建工厂对象
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
//
访问的地址
String helloWorldURL="http://localhost:5200/xfire_sample/services/HelloWorldService";
//
异常处理
try {
//
创建服务对象
IHelloWorldService srvc = (IHelloWorldService) factory.create(srvcModel, helloWorldURL);
//
调用服务中的方法,并显示其结果
System.out.print(srvc.sayHello("dennis"));
//
异常处理
} catch (MalformedURLException e) {
//
显示错误信息
e.printStackTrace();
}
}
}
|
|
<target name="Wsgen">
<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" classpathref="build.classpath" />
<wsgen outputDirectory="build.classpath" wsdl="http://localhost:portno/xfire_sample/services/HelloWorldService?wsdl" package="client" />
</target>
|
|
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>HelloWorldService</name>
<serviceClass>
net.rubyeye.webservicedemo.IHelloWorldService
</serviceClass>
<implementationClass>
net.rubyeye.webservicedemo.HelloWorldServiceImpl
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
</beans>
|
|
package
com.test;
import
javax.jws.WebMethod;
import
javax.jws.WebParam;
import
javax.jws.WebResult;
import
javax.jws.WebService;
@WebService(name="Hello",serviceName="Hello",
targetNamespace="http://www.oksonic.cn/xfire")
public
class Hello {
@WebMethod
@WebResult
public String getName(@WebParam String name){
return "Hello world " + name;
}
}
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<serviceClass>com.test.Hello</serviceClass>
<serviceFactory>jsr181</serviceFactory>
</service>
</beans>
|
1065



被折叠的 条评论
为什么被折叠?



