javaWebservice 简单了解,我们项目中用到javaWebservice为客户端提供接口,
接口类:
@WebService
public interface TestWs{
@WebMethod(action = "getScSjRange")
public String getScSjRange(String jsonStr);
}
接口实现类:
@WebService(endpointInterface = "com.tzinfo.app.test.TestWs", targetNamespace = "http://test.app.tzinfo.com/")// http://+包名逆顺序
public class TestWsImpl implements TestWs{
public String getScSjRange(String jsonStr){
boolean success = true;
String message = "";
String errorCode = "";
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
String nowTime = jsonObject.getString("nowTime");
HhjService hhjScsjService = (HhjScsjService) AppContextUtil.getBean(HhjScsjService.class);
List<String> list =null;
try {
list = hhjScsjService.getScsjRange(nowTime);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JsonConfig cfg = new JsonConfig();
cfg.setIgnoreTransientFields(true);
cfg.addIgnoreFieldAnnotation(JsonlibIgore.class);
return JSONUtilsExt.objects2json(cfg, "success", success, "message", message,"hhjScSj",list, "errorCode", errorCode);
}
}
测试类:
TestClientXxx(){
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
org.apache.cxf.endpoint.Client client = dcf.createClient("http://localhost:9090/test/service/testWsImpl?wsdl");
public void test_getScSjRange(){
try {
Object[] returnValueStrs = client.invoke("getScSjRange","{nowTime:'10:50:00'}");
String returnJson = returnValueStrs == null ? null : (String) returnValueStrs[0];
System.out.println(returnJson);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args){ //有机运行即可测试
TestClientXxxtc = new TestClientXxx();
tc.test_getScSjRange();
}
}