Java Android-WSDL/Ksoap2
关于Ksoap2,我有两个问题 首先,下面是一个XML格式的webservice请求示例 请求:Java Android-WSDL/Ksoap2,java,android,wsdl,xml-parsing,ksoap2,Java,Android,Wsdl,Xml Parsing,Ksoap2,关于Ksoap2,我有两个问题 首先,下面是一个XML格式的webservice请求示例 请求: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my-webservice.com/"> <soapenv:Header/> <soapenv:Body> <web:getBoard>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my-webservice.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<!--Optional:-->
<language></language>
<identification login="" pwd=""/>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
我还需要关于解析器的帮助。
Ksoap2使用哪种解析器?(DOM、SAX)
我用的是好方法吗
感谢您的帮助!
圣诞快乐(顺便说一句)
编辑:
我的问题是发送的xml如下所示:
[...] <login i:type="d:string">mylogin</login><pwd i:type="d:string">mypassword</pwd><language i:type="d:string">FR</language></n0:getBoardTypes></v:Body></v:Envelope>
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("language", "FR");
PropertyInfo info = new PropertyInfo();
info.setName("identification"); // you have to make sure here that the parameter name matches the one in the WSDL, which you havent posted
info.setType(identification.class);
info.setValue(new identification("username", "password"));
request.addProperty(info);
[…]myloginmypasswordFR
鉴于我需要:
[...] <language></language>
<identification login="" pwd=""/>
[…]
:|
编辑2:
嗨,托米斯拉夫,谢谢你的时间和回答! 我试过你的解决办法,但没用 我想我会寄一些东西,比如:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my.api.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<language>FR</language>
<identification login="username" pwd="mypwd"/>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my.api.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<language>FR</language>
<identification>
<login>username</login>
<pwd>mypwd</pwd>
</identification>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
FR
通过您的解决方案,我得到了如下结果:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my.api.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<language>FR</language>
<identification login="username" pwd="mypwd"/>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://my.api.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getBoard>
<language>FR</language>
<identification>
<login>username</login>
<pwd>mypwd</pwd>
</identification>
</web:getBoard>
</soapenv:Body>
</soapenv:Envelope>
FR
用户名
mypwd
我想我要创建一个XML模板…:/ 所以我假设您的服务方法签名类似于
getBoard(String language, identification ident) // parameter names here must match the param names in the code below
其中identification
是一个具有两个字符串属性的类login
和pwd
。如果是这种情况,您可以创建一个新类并实现KVMSerizable,如下所示:
public class identification implements KvmSerializable {
public String login;
public String pwd;
public identification (String login, String pwd) {
this.login = login;
this.pwd = pwd;
}
public Object getProperty(int i) {
switch (i) {
case 0:
return login;
case 1:
return pwd;
}
return null;
}
public int getPropertyCount() {
return 2;
}
public void setProperty(int i, Object o) {
switch (i) {
case 0:
login = o.toString();
break;
case 1:
pwd = o.toString();
break;
}
}
public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
switch (i) {
case 0:
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "login";
break;
case 1:
propertyInfo.type = PropertyInfo.STRING_CLASS;
propertyInfo.name = "pwd";
break;
}
}
}
然后按如下方式添加此属性:
[...] <login i:type="d:string">mylogin</login><pwd i:type="d:string">mypassword</pwd><language i:type="d:string">FR</language></n0:getBoardTypes></v:Body></v:Envelope>
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("language", "FR");
PropertyInfo info = new PropertyInfo();
info.setName("identification"); // you have to make sure here that the parameter name matches the one in the WSDL, which you havent posted
info.setType(identification.class);
info.setValue(new identification("username", "password"));
request.addProperty(info);
有什么问题?addProperty可以添加所有属性。这个代码失败了吗?如果是,例外情况是什么?那么web服务不识别它?嗨,Tomislav,谢谢你的时间和回答!我编辑了我的帖子。再次感谢。按照XML标准,这两种格式的理解应该相同。我不明白为什么它会失败。