android - 如何在 Soap 请求中传递数组参数
问题描述
由于无法按照 .Net Webservice 中的要求在请求中传递正确String[]
的参数而导致的问题Soap
public void SoapKsop2_Api_Call(){
SoapObject request = new SoapObject(namespace, methodName);
request.addProperty("ProcName", "Mr.Abc");
String[] sqlPar = new String[2];
sqlPar[0] = "@FLAG";
sqlPar[1] = "@RDeviNo";
String[] sqlVal = new String[2];
sqlVal[0] = "RDevice";
sqlVal[1] = "123546";
PropertyInfo PrfsqlParaName = getProperty(namespace,"sqlParaName",sqlPar);
PropertyInfo sqlParaValue = getProperty(namespace,"sqlParaValue",sqlVal);
request.addProperty(PrfsqlParaName);
request.addProperty(sqlParaValue);
int TimeOutInSeconds = 1000;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url,TimeOutInSeconds * 1000);
androidHttpTransport.call(soapAction, envelope);
Log.d("test", "request: " + androidHttpTransport.requestDump);
Log.d("test", "response: " + androidHttpTransport.responseDump);
SoapObject result = (SoapObject)envelope.getResponse();
String result = result.getProperty(0).toString();
}
private PropertyInfo getProperty(String NAMESPACE,String name, String[] val) {
PropertyInfo info = new PropertyInfo();
info.name = name;
info.namespace = NAMESPACE;
//VECTOR_CLASS
info.type = PropertyInfo.VECTOR_CLASS;
Vector<String> vct = new Vector<String>();
for (int i = 0; i < val.length; i++)
vct.add(val[i]);
info.setValue(vct);
return info;
}
错误:
SoapFault - faultcode: 'soap:Server' faultstring: 'Server was unable to process request. ---> System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at DmlCall.Save_Edit_Delete(String ProcName, String[] sqlParaName, String[] sqlParaValue) in Web Service line 36
--- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@16ba69a
Soap Object
<Envelope xmlns="schemas.xmlsoap.org/soap/envelope/">;
<Body>
<Save_Edit_Delete xmlns="CnnRestro">
<ProcName>[string?]</ProcName>
<!-- Optional -->
<sqlParaName> <string>[string?]</string> </sqlParaName>
<!-- Optional -->
<sqlParaValue> <string>[string?]</string> </sqlParaValue>
</Save_Edit_Delete>
</Body>
</Envelope>
解决方案
推荐阅读
- python - Docker 容器/映像正在运行但没有端口号
- python-3.x - Selenium webdriver 在无头 Firefox 中缺少点击
- java - 在警报对话框中居中消息
- c# - .NET中具有重复字符和长度的正则表达式
- java - 如何在 Spring Boot 中将 2 个不同 jar 中的 2 个微服务部署到同一个端口
- r - R表函数:如何强制表()的列名输出的顺序
- c++ - C++ Copy_if 使用 lambda
- swift - 根据 UIPickerViewSelection 创建警告
- python - 在熊猫中提取特定值后的文本
- php - 如何在 Heroku multi buildpack php + nodejs 中启动 express 服务器