Soap api calling with ksoap(使用ksoap调用Soap API)
本文介绍了使用ksoap调用Soap API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Android应用中获得适当的响应。我的API原始响应显示在soapUi软件中
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetSourcesResponse xmlns="...">
<GetSourcesResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="ITS" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="ITS">
<xs:complexType>
<xs:sequence>
<xs:element name="CM_CityID" type="xs:int" minOccurs="0"/>
<xs:element name="CM_CityName" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DocumentElement xmlns="">
<ITS diffgr:id="ITS1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<CM_CityID>645</CM_CityID>
<CM_CityName>Ahmednagar</CM_CityName>
</ITS>
<ITS diffgr:id="ITS2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
<CM_CityID>2762</CM_CityID>
<CM_CityName>Airoli</CM_CityName>
</ITS>
</DocumentElement>
</diffgr:diffgram>
</GetSourcesResult>
</GetSourcesResponse>
我调用此接口以获得类似
的响应getResponse
{
getResponseResult=anyType
{
schema=anyType
{
element=anyType
{
complexType=anyType
{
choice=anyType
{
element=anyType
{
complexType=anyType
{
sequence=anyType
{
element=anyType{};
element=anyType{};
};
};
};
};
};
};
};
diffgram=anyType{};
};
}
如何获得正确的原文回复
请帮帮我……提前谢谢
推荐答案
使用Wsdl2代码tool
它是帮助开发人员使用.Net Web服务的Web工具。
- 在
browser
另存为.wsdl扩展中打开上面的schemas
- 上传
file.wsdl
到Wsdl2Code
- 下载自动生成的代码
- 粘贴您的包
- 使用
Service
类从服务器读取、写入和更新
来自Service类的示例代码
public VectorClass ReadMultiple(VectorClass filter,
String bookmarkKey, int setSize, List<HeaderProperty> headers) {
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.implicitTypes = true;
soapEnvelope.dotNet = true;
SoapObject soapReq = new SoapObject(
"urn:microsoft-dynamics-schemas/page/classsName",
"ReadMultiple");
for (int i = 0; i < filter.size(); i++) {
soapReq.addProperty("filter", getSOAPVector(filter, i));
}
// soapReq.addProperty("filter", filter);
soapReq.addProperty("bookmarkKey", bookmarkKey);
soapReq.addProperty("setSize", setSize);
soapEnvelope.setOutputSoapObject(soapReq);
NtlmTransport ntml = new NtlmTransport(url,
SharedPreferenceUtil.getString("userName", "username"),
SharedPreferenceUtil.getString("passWord", "password"),
SharedPreferenceUtil.getString("domainName", "domainname"),
SystemService.domainName);
try {
if (headers != null) {
ntml.call(
"urn:microsoft-dynamics-schemas/page/className/ReadMultiple",
soapEnvelope, headers);
} else {
ntml.call(
"urn:microsoft-dynamics-schemas/page/className/ReadMultiple",
soapEnvelope);
}
Object retObj = soapEnvelope.bodyIn;
if (retObj instanceof SoapFault) {
SoapFault fault = (SoapFault) retObj;
Log.e("Fault", "" + fault);
Exception ex = new Exception(fault.faultstring);
if (eventHandler != null)
eventHandler.Wsdl2CodeFinishedWithException(ex);
} else {
SoapObject result = (SoapObject) retObj; //Soap success response
if (result.getPropertyCount() > 0) {
Object obj = result.getProperty(0);
SoapObject j = (SoapObject) obj;
Log.e("Navpos Header Response", ""+result);
VectorClassName resultVariable = new VectorClassName(
j);
return resultVariable;
}
}
} catch (Exception e) {
if (eventHandler != null)
eventHandler.Wsdl2CodeFinishedWithException(e);
e.printStackTrace();
}
return null;
}
这篇关于使用ksoap调用Soap API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:使用ksoap调用Soap API
猜你喜欢
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01