Im trying to send a PersonalInfo object from android to vb.net using web services. I have the connection as i can send primitive types.
This is what i have so far....
This is the android activity
package com.msc.mynamespace;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import com.msc.mynamespace.db.DatabaseHelper;
import com.msc.mynamespace.model.PersonalInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MyActivity extends DashboardActivity {
DatabaseHelper db ;
TextView textView1;
EditText editText1;
Button button1;
String test;
final String NAMESPACE = "http://mywebnamespace.org/";
final String URL = "http://localhost/MyWebService.asmx";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sync);
db = new DatabaseHelper(this);
}
public void CallWebservice(View v) {
this.SyncPersonalInfo();
}
//starting asynchronus task
private class SyncPersonalInfoTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
//if you want, start progress dialog here
}
@Override
protected String doInBackground(String... urls) {
String webResponse = "";
try{
final String SOAP_ACTION = "http://mywebnamespace.org/SyncPersonalInfo";
final String METHOD_NAME = "SyncPatientInfo";
PersonalInfo pi=db.RetrievePersonalInfo();//this is PersonalInfo object that i get from the database
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("PI");
fromProp.setValue(pi);
fromProp.setType(pi.getClass());
request.addProperty(fromProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
//envelope.addMapping(NAMESPACE, "PersonalInfo",new PersonalInfo().getClass());
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
webResponse = response.toString();
}
catch(Exception e){
Toast.makeText(getApplicationContext(),"Cannot access the web service"+e.toString(), Toast.LENGTH_LONG).show();
}
return webResponse;
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(getApplicationContext(),"Completed...", Toast.LENGTH_LONG).show();
}
}
public void SyncPersonalInfo(View view) {
SyncPersonalInfoTask task = new SyncPersonalInfoTask();
//passes values for the urls string array
task.execute();
}
}
This is the vb.net part
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://mywebnamespace.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class MyWebService
Inherits System.Web.Services.WebService
Public Class PersonalInfo
Public fname As String
Public lname As String
End Class
<WebMethod()> _
Public Function SyncPatientInfo(//what to put here??) As String
//how to manipulate the parameter??
End Function
End Class
I am lost as to how to send the PersonalInfo object and how to receive it on the .net end and then manipulate it Please assist thanking you all in advance
WCFand after you have the generated client code you would have access to complex objects that are marked as<DataContract>in the.svcfile.