【发布时间】:2015-08-06 11:05:25
【问题描述】:
我还是新手。
我使用Asp.net (visual studio) 编写的网络服务将我的 android 应用程序连接到 SQL Server。
我使用了 SOAP,我想访问在 Web 服务中编写的数据并将其放入微调器中。
这是我在 Visual Studio 中的代码(网络服务)
//从库存中获取产品
[WebMethod]
public DataTable getProduct()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["WebConnectionString"].ToString();
conn.Open();
SqlCommand cmd = new SqlCommand("Select SmallDescription from [Product]", conn);
SqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable("getproduct");
dt.Load(reader);
conn.Close();
return dt;
}
这是我的java 代码:
Thread nt = new Thread() {
@Override
public void run() {
// method getproduct
SoapObject request = new SoapObject(NAMESPACE,
METHOD_NAME);
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// result.getPropertyInfo(result, pi);
/**************** HTTP Post ******************/
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
try {
androidHttpTransport.call(
warehouselist_SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
Log.d("Not working", e.toString());
// Toast.makeText(getApplicationContext(),
// "Not working", Toast.LENGTH_LONG).show();
}
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(MainActivity.this, "hola",
Toast.LENGTH_SHORT).show();
TextView e = (TextView) findViewById(R.id.textView5);
SoapObject resultRequestSOAP = (SoapObject) envelope.bodyIn;
SoapObject nameResult = (SoapObject) resultRequestSOAP
.getProperty(0);
int count = nameResult.getPropertyCount();
//e.setText(Integer.toString(count));
StringBuilder stringBuilder = new
StringBuilder();
/*
* Retrieve one property from the complex
* SoapObject response
*/
for (int i = 0; i < count - 1; i++) {
SoapObject simpleSuggestion = (SoapObject)
nameResult.getProperty(i);
stringBuilder.append(simpleSuggestion.getProperty(
"Small Description").toString());
stringBuilder.append("\n");
}
String temp = stringBuilder.toString();
// MY QUEST IS HERE HOW TO DISPLAY IT IN A SPINNER!!!!!!
}
});
}
};
nt.start();
}
});
}
}
谢谢!
【问题讨论】: