java 调用WebService

导入jar包

    org.apache.axis
    axis
    1.4



    org.lucee
    jaxrpc
    1.4.0


    commons-discovery
    commons-discovery
    0.5


    wsdl4j
    wsdl4j
    1.6.2



java方法
public void callMeth() throws RemoteException, javax.xml.rpc.ServiceException, MalformedURLException {
    String url = "http://jsxngx.seu.edu.cn/WebService/ResourceService.asmx";//提供接口的地址
    String soapaction = "http://tempuri.org/";   //命名空间 和webservic中的targetNamespace对应
    String json = "{\n" +
            "    \"UnitCode\": \"320001\",\n" +
            "    \"Account\": \"admin\",\n" +
            "    \"PushTime\": \"201710122523002\",\n" +
            "    \"EvaluationReportMainList\": [\n" +
            "        {\n" +
            "            \"ResourceName\": \"实验资源名称1\",\n" +
            "            \"EvaluationReportList\": [\n" +
            "                {\n" +
            "                    \"UserName\": \"评价人1\",\n" +
            "                    \"UserNo\": \"123\",\n" +
            "                    \"EvaluationContent\": \"评价内容\",\n" +
            "                    \"CreateDate\": \"/Date(1512573800000)/\"\n" +
            "                }\n" +
            "            ]\n" +
            "        },\n" +
            "        {\n" +
            "            \"ResourceName\": \"实验资源名称2\",\n" +
            "            \"EvaluationReportList\": [\n" +
            "                {\n" +
            "                    \"UserName\": \"评价人2\",\n" +
            "                    \"UserNo\": \"124\",\n" +
            "                    \"EvaluationContent\": \"评价内容\",\n" +
            "                    \"CreateDate\": \"/Date(1512573800000)/\"\n" +
            "                }\n" +
            "            ]\n" +
            "        }\n" +
            "    ]\n" +
            "}" ;
    Service service = new Service();
    Call call =  (Call) service.createCall();
    call.setTargetEndpointAddress(new java.net.URL(url));
    call.setOperationName(new QName(soapaction, "AddEvaluationReport"));//命名空间 调用的方法名
    call.addParameter(new QName(soapaction ,"json"), Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);//传递的参数
    call.setReturnType(Constants.XSD_BOOLEAN);//(标准的类型)
    call.setUseSOAPAction(true);
    call.setSOAPActionURI(soapaction + "AddEvaluationReport");
    Boolean aa =(Boolean) call.invoke(new String[]{json});
    System.out.println(aa);//输出返回值
}

你可能感兴趣的:(java 调用WebService)