`
sunzhyng
  • 浏览: 57388 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

xfire开发web service及调用

    博客分类:
  • Web
阅读更多


xfire配置service

<service>
   <name>Hello</name>
   <namespace>myHello</namespace>
   <serviceClass>com.sun.IHello</serviceClass>
   <implementationClass>com.sun.HelloImpl</implementationClass>
   <style>wrapped</style>
   <use>literal</use>
   <scope>application</scope>
</service>

java调用

public static String callWebService()
    {
       
        // Create a metadata of the service
        Service serviceModel = new ObjectServiceFactory()
                .create(IHello.class);
        System.out.println("callSoapServiceLocal(): got service model.");
       
        // Create a proxy for the deployed service
        XFire xfire = XFireFactory.newInstance().getXFire();
        XFireProxyFactory factory = new XFireProxyFactory(xfire);
       
        String serviceUrl = "http://localhost:9000/ws/services/Hello";
       
        IHello client = null;
        try
        {
            client = (IHello) factory.create(serviceModel, serviceUrl);
        }
        catch (MalformedURLException e)
        {
            System.out.println("WsClient.callWebService(): EXCEPTION: "
                    + e.toString());
        }
       
        // Invoke the service
        String serviceResponse = "";
        try
        {
            serviceResponse = client.example("hello world.");
        }
        catch (Exception e)
        {
            System.out.println("WsClient.callWebService(): EXCEPTION: "
                    + e.toString());
            serviceResponse = e.toString();
        }
        System.out.println("WsClient.callWebService(): status=" + serviceResponse);
       
        // Return the response
        return serviceResponse;
    }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics