如何写一个webservice 和消费webservice

戏子无情 提交于 2019-12-12 04:40:58
@WebService(serviceName = "TestWsService",
        targetNamespace = "http://xxxxxx.com/",
        endpointInterface = "xxxxxxx")
public class TestWsServiceImpl implements TestWsService {
    @Override
    @DbLog(code = "test", name = "测试ws接口")
    public String test(String param) {

        System.out.println("入参:"+param);
        return  param;
    }
}

 

@WebService(name = "TestWsService",
        targetNamespace = "http:xxxx.com")
public interface TestWsService {
    /**
     * 保存物料信息
     * @return
     */
    @WebMethod
    String test(String param);

}
消费webservice 
// 创建客户端
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8080/except/webService/test?wsdl");
// 需要密码的情况需要加上用户名和密码
// client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,
// PASS_WORD));
Object[] objects = new Object[0];
try {
  // invoke("方法名",参数1,参数2,参数3....);
  objects = client.invoke("test", "hahhha");
  return "返回数据:" + objects[0];
} catch (java.lang.Exception e) {
  e.printStackTrace();
  return "异常:" + e.getMessage();
}

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!