如何通过url调用CXF Web服务时传递参数

时间:2012-12-11 05:57:23

标签: java web-services cxf

我创建了一个CXF Web服务示例:

@WebService
public interface InterfaceWebService {

    boolean doLogin(@WebParam(name="username")String username,@WebParam(name="password")String password);

}

服务器代码:

public class WebServer {

    protected WebServer() throws Exception {
        // START SNIPPET: publish
        System.out.println("Starting Server");
        WebServiceImpl implementor = new WebServiceImpl();
        String address = "http://192.168.0.76:9000/sample";
        Endpoint.publish(address, implementor);
        // END SNIPPET: publish
    }

    public static void main(String args[]) throws Exception {
        new WebServer();
        System.out.println("Server ready...");

        Thread.sleep(5 * 60 * 5000);
        System.out.println("Server exiting");
        System.exit(0);
    }
}

WebServiceImpl类

@WebService(endpointInterface = "com.nextenders.services.InterfaceWebService",
serviceName = "sample")

public class WebServiceImpl  implements InterfaceWebService{    


    @Override
    public boolean doLogin(String username, String password) {
          //Here some business logic call
        return true;
    }


}

现在我试图通过以下网址调用此网络服务: 的 http://192.168.0.76:9000/sample/services/doLogin?username=abc&password=abc

但是我得到了wsdl xml结构。但我只需要特定的方法结果!! 我在这里做错了吗?如何在CXF webservice中传递参数?

1 个答案:

答案 0 :(得分:2)

问题解决了。我忘记了服务名称并尝试访问直接方法。

<强> http://192.168.0.76:9000/sample/services/login_service/doLogin?username=abc&password=abc