0
我有一个应用程序连接到我们的.NET Web服务,我发现我们为每个Web服务方法创建了相同的方法,但唯一的区别是参数和Web服务方法。我正在寻找一种方法来让以下方法接受参数,然后管理1个和多个参数可能会更有用。将参数传递给SOAP方法
当前方法 * NameSpace,URL,argName,argValue全部定义在类的顶部。
public static Document GetTickets() {
try {
SoapObject request = new SoapObject(NameSpace, "GetTickets");
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
request.addProperty(argName, argValue);
request.addProperty("Customer", "ABC");
request.addProperty("Local", "USA");
envelope.setOutputSoapObject(request);
androidHttpTransport.call("RemoteWebService/GetTickets", envelope);
SoapPrimitive responseData = (SoapPrimitive) envelope.getResponse();
if (responseData != null)
{
//get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
//parse using builder to get DOM representation of the XML file
InputSource is = new InputSource(new StringReader(responseData.toString()));
return db.parse(is);
}
else
return null;
}
catch (Exception e)
{
Errors.LogError(e);
return null;
}
}
我想它是沿着这些路线的东西:
public static Document GetTickets(String WebServiceMethod, ArrayList Params) {
try {
SoapObject request = new SoapObject(NameSpace, WebServiceMethod);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
//Syntax is wrong, I know, but just want to show what I'm looking to do:
foreach(Parameter p in Params)
request.addProperty(p[0].value, p[1].value);
envelope.setOutputSoapObject(request);
androidHttpTransport.call("RemoteWebService/" + WebServiceMethod, envelope);
SoapPrimitive responseData = (SoapPrimitive) envelope.getResponse();
if (responseData != null)
{
//get the factory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//Using factory get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
//parse using builder to get DOM representation of the XML file
InputSource is = new InputSource(new StringReader(responseData.toString()));
return db.parse(is);
}
else
return null;
}
catch (Exception e)
{
Errors.LogError(e);
return null;
}
}
我已经尝试了一些不同的尝试,在这一点,但获得了大量的错误。我知道这很简单,但似乎无法弄清楚atm。
你可以发布错误? – rodrigoap 2012-03-06 18:16:37
好吧,正如我所说的,我尝试过使用数组,多维数组和其他几个数组,但是不断得到索引超出范围错误,我知道这意味着被访问的元素的索引超出范围阵列的边界,但是我对此非常沮丧,以致于我删除了所有内容并再次从头开始。非常抱歉,我没有方便的错误。 – Robert 2012-03-06 18:28:31