【发布时间】:2014-04-19 05:58:59
【问题描述】:
我正在 Android 中发出 SOAP 请求。我到底想要实现的是:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:GeneratePin>
<tem:sEmail>xyz@abc.com</tem:sEmail>
<tem:sFlage>true</tem:sFlage>
</tem:GeneratePin>
</soap:Body>
</soap:Envelope>
但我得到了:
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding" xmlns:v="http://www.w3.org/2003/05/soap-envelope">
<v:Header />
<v:Body>
<tem:GeneratePin xmlns="http://www.tempuri.org/">
<tem:sEmail>abc@xyz.com</tem:sEmail>
<tem:sFlage>true</tem:sFlage>
</tem:GeneratePin>
</v:Body>
</v:Envelope>
我正在使用以下代码:
static String SOAP_ACTION = "http://tempuri.org/GeneratePin";
static String namespace = "http://www.tempuri.org/";
private static String url = "xyz";
static SoapObject request = null;
static SoapSerializationEnvelope envelope;
static HttpTransportSE androidHttpTransport;
// MethodName variable is define for which webservice function will call
public static String getPin(String MethodName) {
try {
request = new SoapObject(namespace, "tem:GeneratePin");
/*
* PropertyInfo pi = new PropertyInfo(); pi.setName("sEmail");
* pi.setValue("rishabh@vervesys.local"); request.addProperty(pi);
*
* PropertyInfo pi1 = new PropertyInfo(); pi1.setName("sFlage");
* pi1.setValue("true"); request.addProperty(pi1);
*/
request.addProperty("tem:sEmail", "abc@xyz.com");
request.addProperty("tem:sFlage", "true");
System.out.println("request is : == " + request);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.encodingStyle = "utf-8";
envelope.setOutputSoapObject(request);
/*
* MarshalDouble marshaldDouble = new MarshalDouble();
* marshaldDouble.register(envelope);
*/
androidHttpTransport = new HttpTransportSE(url);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
System.out
.println("ONE!@#$%^& " + androidHttpTransport.requestDump);
/*
* androidHttpTransport
* .setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
*/
final SoapPrimitive response = (SoapPrimitive) envelope
.getResponse();
Log.i("Webservice Output", response.toString());
return response.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
【问题讨论】:
-
你在使用 KSOAP 库吗?
-
是的..你还有其他图书馆吗?
-
不,我也使用 KSOAP。虽然是第 3 版。从来没有这个问题。 ://
-
我只想要soap作为前缀而不是v。你可以试试我的代码看看问题。
-
是的,我明白了。标签不一样。但这似乎从来没有对我造成问题。如果您浏览网络,您会注意到每个人都有标签
<v>。 只是说
标签: android soap ksoap2 android-ksoap2