我的KSOAP2 for Android有依赖于Android设备的问题。
我按照了seeharpgears http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html
的说明我有一个带有此功能的Embarcadero C ++ Builder XE2服务器来传递复杂的数据类型。
功能如下:
我试图创建一个虚假方法,以回复他的请求。
我创建了一个名为Category的类。
但我不知道为什么,我仍然收到数据类型为vector的数据:
这是我的代码:
public void getSettings(String sessionId){
SoapObject Request = new SoapObject(ProgramSettings.NAMESPACE, "GetCategoryById");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(Request);
Category C = new Category();
envelope.addMapping("urn:@:TrackNavMobile", "Category",new Category().getClass());
// addMapping("urn:@:TrackNavMobile", "Category", cat.getClass());
String url="http://" + readIp() + ":" + readPort() +"/soap/ITrackNavMobile";
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);
/*
* Call the web service and retrieve result ... how luvly <3
*
* */
try
{
androidHttpTransport.call(ProgramSettings.SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.bodyIn;
//TextView tv = (TextView)findViewById(R.id.textView1);
for(int i=0;i<response.getPropertyCount();i++)
{
new AlertDialog.Builder(this)
.setMessage(response.getProperty(0).toString())
.setNeutralButton("OKi", null)
.show();
//if complex type is present then you can cast this to SoapObject and if primitive type is returned you can use toString() to get actuall value.
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
这是属性的结果......当我调试它时,调用用Java编写的setCategory方法,并使用正确的值......但它不会返回它们。 [分类:it.comtec.Category@44f02ea0,返回:it.comtec.Category@44f02ea0]
这是我的服务器虚拟方法,名为:
Category* TTrackNavMobileImpl::GetCategoryById(){
Category* setup= new Category();
setup->Name="Thomas";
setup->CategoryId=1;
setup->Description="Test1";
return setup;
}
这是RequestDump:
<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>
<n0:GetCategoryById id="o0" c:root="1"
sessionId="FFEF196A3940136D7C141C4F01965D7D"
xmlns:n0="http://tempuri.org/" />
</v:Body>
</v:Envelope>
这是ResponseDump:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:NS1="urn:TrackNavMobile-ITrackNavMobile">
<NS1:GetCategoryByIdResponse xmlns:NS2="urn:@:TrackNavMobile">
<NS2:Category id="1" xsi:type="NS2:Category">
<Name xsi:type="xsd:string">Thomas</Name>
<Description xsi:type="xsd:string">Test1</Description>
<CategoryId xsi:type="xsd:int">1</CategoryId>
</NS2:Category><return href="#1"/>
</NS1:GetCategoryByIdResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
有人有想法吗?
答案 0 :(得分:0)
您必须使用getResponse()而不是bodyIn。更多细节在网站上链接的各种博客文章中,也可以直接在维基上发布。您必须手动或使用编组来实现响应的解析。
答案 1 :(得分:0)
不知道这是否与您的问题有关,但在您循环查看响应属性并在警告对话框中显示它们的示例代码中,您正在调用
.setMessage(response.getProperty(0)的ToString())
什么时候应该
.setMessage(response.getProperty(ⅰ)的ToString())