I want to insert data into sql server from android application.For this i am using wcf service below is the code i had written in wcf service
[OperationContract]
[WebInvoke(UriTemplate = "GetAllReportsMethod?spName={spName}&inputxele={inputxele}&transType={transType}",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Xml)]
XElement GetAllReportsMethod(string spName, string inputxele, string transType);
From android side i had written below code:
String username=user.getText().toString();
String password=pass.getText().toString();
String inputxele="LoginData UserName='"+username+"' UserPassword='"+password+"'";
String sp="USP_AreaMst";
String tt="CreateLoginData";
String url="http://10.0.2.2/JsonWcfService/GetEmployees.svc/GetAllReportsMethod?";
String parameters="spName="+URLEncoder.encode(sp)+"&inputxele="+URLEncoder.encode(inputxele)+"&transType="+URLEncoder.encode(tt);
InputStream instream =null;
String resultdata=null;
try
{
ArrayList<namevaluepair> nameValuePairs = new ArrayList<namevaluepair>();
nameValuePairs.add(new BasicNameValuePair("spName", sp));
nameValuePairs.add(new BasicNameValuePair("inputxele", inputxele));
nameValuePairs.add(new BasicNameValuePair("transType", tt));
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 20000);
HttpConnectionParams.setSoTimeout(httpParameters, 20000);
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpPost post=null;
try
{
post=new HttpPost(url);
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(post);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK)
{
HttpEntity entity = response.getEntity();
Toast.makeText(MainActivity.this, "Data Inserted sucessfully", Toast.LENGTH_LONG).show();
instream.close();
}
else
{
Toast.makeText(MainActivity.this, "Incorrect data", Toast.LENGTH_LONG).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
catch (Exception e)
{
e.printStackTrace();
}
Any help please i had stucked from past couple of days...