Java 来自Android应用程序的WCF服务方法调用
我需要调用具有SOAP信封的WCF服务,如下所示:Java 来自Android应用程序的WCF服务方法调用,java,android,wcf,service,Java,Android,Wcf,Service,我需要调用具有SOAP信封的WCF服务,如下所示: 会话启动 urn:uuid:eca7579d-5581-4989-984d-0ead2e670194 http://www.w3.org/2005/08/addressing/anonymous http://[WCF服务URL].svc 会话管理请求 ; IMEI123456/IMEI&xD; 公务员编号a/公务员编号 ; 密码aa/密码 ; 状态设置/状态和xD; usernamea/UserName ; XSDV
会话启动
urn:uuid:eca7579d-5581-4989-984d-0ead2e670194
http://www.w3.org/2005/08/addressing/anonymous
http://[WCF服务URL].svc
会话管理请求
;
IMEI123456/IMEI&xD;
公务员编号a/公务员编号
;
密码aa/密码
;
状态设置/状态和xD;
usernamea/UserName
;
XSDVersion1/XSDVersionxd;
/会话管理请求
我正在努力解决的部分是获取XMLMessage SOAPObject的值。下面是我的代码示例:
public static String requestSessionManagement() throws Exception
{
int i;
int timeout;
PropertyInfo pi;
HttpTransportSE transport;
String soap_action;
String method = "GetData";
String result = "";
timeout = ServerInterface.TIMEOUT;
soap_action = _soap_namespace + method;
// Check array to know if custom timeout is needed
for (i = 0;i < func_timeouts.length;i++)
{
if (func_timeouts[i][0].compareTo(method) == 0)
{
timeout = Integer.parseInt(func_timeouts[i][1]);
}
}
Log.i("[ServerInterface]", "sending request to "+_server_url+": "+_soap_namespace+method);
Log.i("[ServerInterface]", "timeout: "+timeout);
// Build request
SoapObject request = new SoapObject(_soap_namespace, "XMLMessage");
MapRequestSessionManagement param1 = new MapRequestSessionManagement();
param1.imei = "123456";
param1.officer_number = "1029384";
param1.password = "test1!";
param1.status = "Setup";
param1.username = "MichaelJS";
param1.xsd_version = "1";
pi = new PropertyInfo();
pi.setName("SessionManagementRequest");
pi.setValue(param1);
pi.setType(MapRequestSessionManagement.MAPREQUESTSESSIONMANAGEMENT_CLASS);
request.addProperty(pi);
// Build envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);// Soap version must match server implementation
//Prepare header
envelope.headerOut = new Element[4];
envelope.headerOut[0] = ServerSyncHelper.buildActionHeader("SessionStart");
envelope.headerOut[1] = ServerSyncHelper.buildMessageIDHeader();
envelope.headerOut[2] = ServerSyncHelper.buildReplyToHeader("http://www.w3.org/2005/08/addressing/anonymous");
envelope.headerOut[3] = ServerSyncHelper.buildToHeader(_server_url);
envelope.dotNet = true; // Must set this if the server is implemented on the dotnet framework
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
// Set http transport
transport = new HttpTransportSE(_server_url, timeout);
transport.debug = true; //this is optional, use it if you don't want to use a packet sniffer to check what the sent message was (httpTransport.requestDump, httpTransport.responseDump)
try
{
transport.call(soap_action, envelope);
Log.i("[ServerInterface]", "request dump "+transport.requestDump);
Log.i("[ServerInterface]", "response dump "+transport.responseDump);
Log.i("[ServerInterface]", "response "+envelope.bodyIn);
String response = (String)envelope.getResponse();
result = ""+response;
}
catch (Exception e)
{
Log.i("[ServerInterface]", "Exception part");
Log.i("[ServerInterface]", "request dump "+transport.requestDump);
Log.i("[ServerInterface]", "response dump "+transport.responseDump);
Log.e("[ServerInterface]", "Error with soap transmition "+e);
e.printStackTrace();
}
return result;
}
public静态字符串requestSessionManagement()引发异常
{
int i;
int超时;
房地产信息;
httpse转运;
字符串soap_动作;
String method=“GetData”;
字符串结果=”;
timeout=ServerInterface.timeout;
soap\u action=\u soap\u名称空间+方法;
//检查数组以了解是否需要自定义超时
对于(i=0;i
当我运行上述代码时,我得到以下结果,这是正确的。但是,我不确定如何根据服务器要求进行格式化:
会话启动
urn:uuid:49bd428d-188a-4035-8d8f-45bcb42b37ec
http://www.w3.org/2005/08/addressing/anonymous
http://41.134.120.203/MobileInterfaceService/SessionManagementService.svc
123456
1029384
测试1!
安装程序
迈克尔斯
1.
似乎他们已将服务器方法编码为接受一个字符串参数,该参数包含SessionManagementRequest对象的XML结构。您所说的“SOAP信封如下”是什么意思?另外:你的实际问题是什么?你所说的“肥皂信封如下”是什么意思?另外:你的实际问题是什么?