[英]How to authenticate to webservice using KSOAP Android library
I am in the middle of understanding android programming in particular and I just want to create a simple POC on how to call SOAP based web service from an android app. 我特别了解android编程,我只想创建一个简单的POC,以了解如何从android应用程序调用基于SOAP的Web服务。
Based on my readings, I can used this library KSOAP2 根据我的阅读,我可以使用该库KSOAP2
I haven't done serious coding yet but I just would like to know how to implement authentication using this library. 我尚未进行认真的编码,但我只想知道如何使用此库来实现身份验证。
In the examples that I have seen on the net, almost all of them has no authentication mechanism. 在网上看到的示例中,几乎所有示例都没有身份验证机制。 If my web service requires authentication such as a userid/password then how can I pass it along using this library. 如果我的Web服务需要身份验证(例如用户ID /密码),那么如何使用此库将其传递。
Just would like a lead to start on. 只是想开始。 Thanks 谢谢
With regards to the second part of your questions my webservice is in vb.net and requires a username and password so i have a webmethod that handles that. 关于您的问题的第二部分,我的网络服务位于vb.net中,需要用户名和密码,因此我有一个可以处理该问题的网络方法。 This is the android side that handles it... There is also an adapter but Ill let you get that part. 这是处理它的android方面...还有一个适配器,但我会让你得到这一部分。
public Account getAccountFromWebservice() {
SOAP_ACTION = "getAccount";
METHOD_NAME = "getAccount";
SoapObject Request = new SoapObject(Data.NAMESPACE, METHOD_NAME);
String username = "name";
String password = "something";
PropertyInfo username = new PropertyInfo();
username .setName("username ");
username .setValue(username);
Request.addProperty(username );
PropertyInfo password = new PropertyInfo();
password.setName("password ");
password.setValue(password );
Request.addProperty(password );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
HttpTransportSE HttpTransport = new HttpTransportSE(Data.URL);
try {
HttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
for (int i = 0; i < response.getPropertyCount(); i++) {
account.setProperty(i, response.getProperty(i).toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return account;
}
and here is a part of the .net webervice method 这是.net Webervice方法的一部分
public Accounts[] getAccounts(String username, String password)
{
strSQL = "dbo.danceworks_getAccounts";
SqlParameter[] sp = new SqlParameter[2];
sp[0] = new SqlParameter("@username", username);
sp[1] = new SqlParameter("@password", password);
DatabaseCore dc = new DatabaseCore();
DataSet ds = new DataSet();
ds = dc.ExecSPReturnDS(strSQL, sp);
Accounts[] account= new Accounts[ds.Tables[0].Rows.Count];
int i;
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
account[i] = new Accounts();
Accounts[i].add the various fields for an account object
}
return Classes;
}
Hope that helps 希望能有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.