xfire开发web service及调用


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;
    }

你可能感兴趣的:(Web,sun)