如何从Android到SOAP网络服务的传递对象吗? [英] How to pass object from android to soap web service?
本文介绍了如何从Android到SOAP网络服务的传递对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从Android电子传递一个对象,以SOAP Web服务,但我得到一个错误的驱动程序对象为空。我怎么能传递一个对象到SOAP Web服务没有得到这个错误?
下面是对象:
<肥皂:身体与GT;
< CreateDriver的xmlns =http://tempuri.org/>
< objDriver>
<状态>&INT LT; /状态>
< DriverId>&LT INT; / DriverId>
<&名字GT;串LT; /姓>
<&姓氏GT;串LT; /姓氏>
<获得code>串LT; /访问code>
<图片和GT;串LT; /图片>
<签署及GT;串LT; /签署及GT;
<电子邮件和GT;串LT; /电子邮件与GT;
<电话和GT;串LT; /手机>
<状态>&INT LT; /状态>
< CreationDate>及日期时间LT; / CreationDate>
<&时间modificationdate GT;及日期时间LT; /时间modificationdate>
< CreatedUserId>&LT INT; / CreatedUserId>
< CreatedUser>
<状态>&INT LT; /状态>
<用户名>&LT INT; /用户名>
<&名字GT;串LT; /姓>
<&姓氏GT;串LT; /姓氏>
<用户名>串LT; /用户名>
<密码和GT;串LT; /密码>
< ConfirmPassword>串LT; / ConfirmPassword>
< UserMail>串LT; / UserMail>
< CreationDate>及日期时间LT; / CreationDate>
<&时间modificationdate GT;及日期时间LT; /时间modificationdate>
<状态>&INT LT; /状态>
< CreatedUserId>&LT INT; / CreatedUserId>
< ModifiedUserId>&LT INT; / ModifiedUserId>
< / CreatedUser>
< ModifiedUserId>&LT INT; / ModifiedUserId>
< ModifiedUser>
<状态>&INT LT; /状态>
<用户名>&LT INT; /用户名>
<&名字GT;串LT; /姓>
<&姓氏GT;串LT; /姓氏>
<用户名>串LT; /用户名>
<密码和GT;串LT; /密码>
< ConfirmPassword>串LT; / ConfirmPassword>
< UserMail>串LT; / UserMail>
< CreationDate>及日期时间LT; / CreationDate>
<&时间modificationdate GT;及日期时间LT; /时间modificationdate>
<状态>&INT LT; /状态>
< CreatedUserId>&LT INT; / CreatedUserId>
< ModifiedUserId>&LT INT; / ModifiedUserId>
< / ModifiedUser>
< / objDriver>
< bytArrPicture>&base64Binary的LT; / bytArrPicture>
< bytArrSignature>&base64Binary的LT; / bytArrSignature>
< / CreateDriver>
< / SOAP:身体与GT;
< / SOAP:信封>
下面是我的code:
公共无效POSTDATA()抛出IOException异常,XmlPullParserException {
CreateDriver cDriver =新CreateDriver();
cDriver.setFirstName(N);
cDriver.setLastName(N);
SoapObject objDriver =新SoapObject空间(namespace,METHOD_NAME);
objDriver.addProperty(姓中,n);
objDriver.addProperty(姓氏,N); //请求。
// request.addProperty(CreateDriverSimple,请求);
HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
SoapSerializationEnvelope信封=新SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(objDriver);
envelope.dotNet = TRUE; //这是一个将调用WebService的实际部件
androidHttpTransport.call(SOAP_ACTION,信封);
SoapObject结果=(SoapObject)envelope.bodyIn;
解决方案
检查这个线索,他也有类似的问题和解决方案在那里提供<一个href=\"http://stackoverflow.com/questions/7814164/android-ksoap2-parameter-issues/7814380#7814380\">Android ksoap2参数问题
SoapObject要求=新SoapObject空间(namespace,METHOD_NAME); //使用这个添加参数
//request.addProperty(\"Parameter\",\"Value); //声明SOAP请求的版本
SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(请求); //需要让互联网电话
HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
尝试{
//这是一个将调用WebService的实际部件
androidHttpTransport.call(SOAP_ACTION,信封);
}赶上(例外五){
e.printStackTrace();
} //从信封身体SOA的presult。
SoapObject结果=(SoapObject)envelope.bodyIn;
I need to pass an object from android to a soap web service, but I get an error that the driver object is null. How can I pass an object to the soap web service without getting this error?
Here is the object:
<soap:Body>
<CreateDriver xmlns="http://tempuri.org/">
<objDriver>
<status>int</status>
<DriverId>int</DriverId>
<FirstName>string</FirstName>
<LastName>string</LastName>
<AccessCode>string</AccessCode>
<Picture>string</Picture>
<Signature>string</Signature>
<Email>string</Email>
<Phone>string</Phone>
<Status>int</Status>
<CreationDate>dateTime</CreationDate>
<ModificationDate>dateTime</ModificationDate>
<CreatedUserId>int</CreatedUserId>
<CreatedUser>
<status>int</status>
<UserID>int</UserID>
<FirstName>string</FirstName>
<LastName>string</LastName>
<UserName>string</UserName>
<Password>string</Password>
<ConfirmPassword>string</ConfirmPassword>
<UserMail>string</UserMail>
<CreationDate>dateTime</CreationDate>
<ModificationDate>dateTime</ModificationDate>
<Status>int</Status>
<CreatedUserId>int</CreatedUserId>
<ModifiedUserId>int</ModifiedUserId>
</CreatedUser>
<ModifiedUserId>int</ModifiedUserId>
<ModifiedUser>
<status>int</status>
<UserID>int</UserID>
<FirstName>string</FirstName>
<LastName>string</LastName>
<UserName>string</UserName>
<Password>string</Password>
<ConfirmPassword>string</ConfirmPassword>
<UserMail>string</UserMail>
<CreationDate>dateTime</CreationDate>
<ModificationDate>dateTime</ModificationDate>
<Status>int</Status>
<CreatedUserId>int</CreatedUserId>
<ModifiedUserId>int</ModifiedUserId>
</ModifiedUser>
</objDriver>
<bytArrPicture>base64Binary</bytArrPicture>
<bytArrSignature>base64Binary</bytArrSignature>
</CreateDriver>
</soap:Body>
</soap:Envelope>
Here is my code:
public void postData() throws IOException, XmlPullParserException {
CreateDriver cDriver = new CreateDriver();
cDriver.setFirstName("n");
cDriver.setLastName("n");
SoapObject objDriver = new SoapObject(NAMESPACE, METHOD_NAME);
objDriver.addProperty("FirstName", "n");
objDriver.addProperty("LastName", "n");
// request.
// request.addProperty("CreateDriverSimple",request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(objDriver);
envelope.dotNet = true;
// this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
解决方案
check this thread, he had similar problem and the solution was provided there Android ksoap2 parameter issues
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Use this to add parameters
//request.addProperty("Parameter","Value");
//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
//Needed to make the internet call
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;
这篇关于如何从Android到SOAP网络服务的传递对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文