Click here to Skip to main content
15,884,989 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


C#
[OperationContract]
        [WebInvoke(UriTemplate = "GetAllReportsMethod?spName={spName}&inputxele={inputxele}&transType={transType}",
            BodyStyle = WebMessageBodyStyle.Wrapped,
            ResponseFormat = WebMessageFormat.Xml)]
        //method
        XElement GetAllReportsMethod(string spName, string inputxele, string transType);


From android side i had written below code:

Java
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));
        //post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
        //post.setEntity(new StringEntity(nameValuePairs.toString()));
        //post.setEntity(new StringEntity(parameters));
        // Execute HTTP Post Request
        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...
Posted
Updated 29-Jan-15 3:02am
v2
Comments
Tejas Vaishnav 29-Jan-15 9:03am    
What error your are facing?
Raghu Golla 29-Jan-15 23:54pm    
method not allowed
Afzaal Ahmad Zeeshan 29-Jan-15 10:12am    
Yes, you can send multiple parameters to the WCF service from any device; even Android. You just need to modify your current running WCF application to allow more parameters in its functions.
Raghu Golla 29-Jan-15 23:55pm    
what are the modifications i have to done in wcf code?
Raghu Golla 29-Jan-15 23:52pm    
Method not allowed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900