这个是甲方webService接口里的说明(浏览器打开.asmx地址)
我在postman里面按照同样的格式去请求可以得到正确的响应
但是在我的代码里面,传值就出了问题,不知道问题在哪,求助各位大佬,感激不尽
private static String sendReq(String reqXML)
{
try {
String namespace = "http://tempuri.org/";
String method = "Test";
String url = "http://ip/BDCZZCX.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(url));
//命名空间和调用接口的方法名
call.setOperationName(new javax.xml.namespace.QName(namespace, method));
//call.setReturnType(new QName(namespace,method), String.class);
call.setUseSOAPAction(true);
//call.addParameter(new QName(namespace, method), XMLType.XSD_STRING, ParameterMode.IN);
// 设置返回类型
//call.addParameter();
call.setSOAPActionURI(namespace+method);
String respXML="";
// 使用invoke调用方法,Object数据放传入的参数值(可多个)
Object[] s = new Object[] {reqXML};
respXML =(String) call.invoke(s);
logger.debug("响应"+respXML);
return respXML;
} catch (Exception e) {
System.out.println("报错:");
e.printStackTrace();
}
return null;
}
以下是我传的 参数 reqXML
reqXML.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <soap:Body>\n" +
" <Test xmlns=\"http://tempuri.org/\">\n" +
" <name>xxx</name>\n" +
" <certNo>42xxxxxxxxxxxxxx14</certNo>\n" +
" <xzdm>123</xzdm>\n" +
" </Test>\n" +
" </soap:Body>\n" +
"</soap:Envelope>");
得到的响应是
响应<Response><Header><FunCode>1110</FunCode><Status>2</Status><ResultMsg>startIndex cannot be larger than length of string.
Parameter name: startIndex</ResultMsg></Header><Body><QueryID /><SJMM /><YWLX /><YWZH /><SQR /><CJR /><ZT /></Body></Response>
最后解决:
传xml时,需要将xml中的特殊字符进行转义
< 换成 <
> 换成 >
& 换成 &
' 换成 '
" 换成 "
空格 换成