有一个用 .net 编写的 Web 服务...我单独添加了一个标头方法。为了安全。有四个参数。我还解析了我 var.burada 的 XML 代码 如何使用 SOAP 标头
谢谢..
我的网络服务标头:.net webservice
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Header>
<GuvenlikProtokolu xmlns="http://www.xxx.net/">
<prm1>string</prm1>
<prm2>string</prm2>
<prm3>string</prm3>
<prm4>string</prm4>
</GuvenlikProtokolu>
</soap:Header>
<soap:Body>
xml解析代码在这里:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.w3c.dom.Document;
import org.w3c.dom.Element; // using.....
import org.w3c.dom.NodeList;
…………
public List<classCust> GetCust(Integer X_ID) {
List<classCust> list = null;
SOAP_ACTION = "http://www.xxx.net/GetCust";
METHOD_NAME = "GetCust";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("X_ID", X_ID);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
SoapPrimitive result = null;
try {
httpTransport.call(SOAP_ACTION, envelope);
result = (SoapPrimitive) envelope.getResponse();
XMLParser parser = new XMLParser();
String xml = result.toString();
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName("ITEM");
list = new ArrayList<classCust>();
for (int i = 0; i < nl.getLength(); i++) {
classCust item = new classCust();
Element e = (Element) nl.item(i);
item.setID(Integer.parseInt(parser.getValue(e, "ID")));
item.setNAME(parser.getValue(e, "NAME"));
list.add(item);
}
} catch (Exception e) {
e.printStackTrace();
Log.i("Error : ", e.getMessage().toString());
list = null;
}
return list;
}