我正在开发一个将 Android 驱动的设备连接到 .NET wcf 服务器的项目。
我遇到的问题是 SOAP 信封的布局。当我使用soapUI 发送请求时,请求得到了正确处理。但是,当我在 Android 上使用 Ksoap2 时,我在 SOAP 返回信封中得到一个空值作为返回值,服务器记录了一个 HTTP 代码 = 200(OK)的请求。
如何设置 KSOAP2 以创建与soapUI 中使用的相同的 SOAP 信封?
这是一个使用soapUI 的工作请求。这就是布局的外观。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetPerson>
<tem:name>Roel</tem:name>
</tem:GetPerson>
</soapenv:Body>
</soapenv:Envelope>
并返回soapUI
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetPersonResponse xmlns="http://tempuri.org/">
<GetPersonResult xmlns:a="http://schemas.datacontract.org/2004/07/StageService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Age>21</a:Age>
<a:Name>Roel</a:Name>
</GetPersonResult>
</GetPersonResponse>
</s:Body>
</s:Envelope>
我做了一个肥皂信封的转储。当我从 Android 应用程序发送布局时,这就是现在的布局。
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<GetPerson xmlns="http://tempuri.org/" id="o0" c:root="1">
<n0:name i:type="d:string" xmlns:n0="tem">Roel</n0:name>
</GetPerson>
</v:Body>
</v:Envelope>
以及这个请求的回邮信封
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetPersonResponse xmlns="http://tempuri.org/">
<GetPersonResult i:nil="true" xmlns:a="http://schemas.datacontract.org/2004/07/StageService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
</GetPersonResponse>
</s:Body>
</s:Envelope>
谁能解释我如何使输出布局与我从soapUI 发送的布局相同?
我来自完整应用程序的代码:
private static final String SOAP_ACTION = "http://tempuri.org/IService1/GetPerson";
private static final String METHOD_NAME = "GetPerson";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.4.231/TestWebservice/Service1.svc?wsdl";
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
Log.e("debug","Creating new soap object");
PropertyInfo pi = new PropertyInfo();
pi.setNamespace("tem");
pi.setName("name");
pi.setValue("Roel");
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
Log.e("debug","Creating new soap envelope");
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
Log.e("debug","setoutput soap object");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.13.8", 8080));
HttpTransportSE androidHttpTransport = new HttpTransportSE(proxy, URL);
Log.e("debug","new http transport init");
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.e("debug","http transport call");
System.out.println(androidHttpTransport.requestDump);
System.out.println(androidHttpTransport.responseDump);
SoapObject result = (SoapObject)envelope.getResponse();
Log.e("debug","get response");
tv.setText( ""+result);
} catch (Exception e) {
tv.setText(e.getMessage());
Log.e("error","somthing went wrong!!");
e.toString();
System.out.println(e);
}
提前致谢,
费边