我想使用可用的ksoap庫將我的Android應用程序中的數組傳遞給SOAP Web服務。將數組傳遞到SOAP Web服務以插入遠程數據庫
我的數組是這樣的:
String[] values={"abc","def"};
如何通過這個作爲參數傳遞給我的web服務調用?
任何人都可以幫我嗎?
這是我的web服務代碼:
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public String getnames(String[] values)
{
try
{
using (SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123"))
{
int count = 1;
int rows = 0;
myConnection.Open();
foreach (string student in values)
{
count++;
using (SqlCommand myCommand = new SqlCommand())
{
myCommand.Connection = myConnection;
myCommand.CommandText = "insert into record values(@pCount, @pStudent)";
SqlParameter param = myCommand.CreateParameter();
param.ParameterName = "@pCount";
param.Value = count;
myCommand.Parameters.Add(param);
param = myCommand.CreateParameter();
param.ParameterName = "@pSudent";
param.Value = student;
rows = myCommand.ExecuteNonQuery();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return "an error occured";
}
return "success";
}
}
}
我的logcat:
11-10 12:26:56.159: INFO/System.out(334): ----null
11-10 12:26:56.159: DEBUG/AndroidRuntime(334): Shutting down VM
11-10 12:26:56.159: WARN/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): FATAL EXCEPTION: main
11-10 12:26:56.179: ERROR/AndroidRuntime(334): java.lang.NullPointerException
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at com.example.display.call2(display.java:193)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at com.example.display$3.onClick(display.java:146)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at android.view.View.performClick(View.java:2408)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at android.view.View$PerformClick.run(View.java:8816)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at android.os.Handler.handleCallback(Handler.java:587)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at android.os.Handler.dispatchMessage(Handler.java:92)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at android.os.Looper.loop(Looper.java:123)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at java.lang.reflect.Method.invokeNative(Native Method)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at java.lang.reflect.Method.invoke(Method.java:521)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-10 12:26:56.179: ERROR/AndroidRuntime(334): at dalvik.system.NativeStart.main(Native Method)
11-10 12:26:56.189: WARN/ActivityManager(58): Force finishing activity com.example/.display
在此先感謝
看到logcat我貼 –
line no 334 is System.out.println(「----」+ responddata); –
我的代碼:http://pastie.org/2840334 –