Note that there are some explanatory texts on larger screens.

plurals
  1. POvb.net asmx WebService to accept JSON in HTTP-POST using Android
    primarykey
    data
    text
    <p>I am trying to post data to my server (vb.net) using mobile devices. I've researched several great articles on the client-side (Android) including this <a href="http://encosia.com/using-complex-types-to-make-calling-services-less-complex/" rel="nofollow noreferrer">Encosia article</a> and <a href="https://stackoverflow.com/questions/3027066/how-to-send-a-json-object-over-request-with-android">sending JSON object with Android</a>.</p> <p>I have created a sample class:</p> <pre><code>Public Class OneEvaluation Private strEmail As String Public Property email() As String Get Return strEmail End Get Set(ByVal value As String) strEmail = value End Set End Property Private strPassword As String Public Property password() As String Get Return strPassword End Get Set(ByVal value As String) strPassword = value End Set End Property End Class </code></pre> <p>and I've created my webmethod:</p> <pre><code>Public Class AsmxCodebehind Inherits System.Web.Services.WebService &lt;WebMethod()&gt; _ Public Function AndroidTest(ByVal JSON As OneEvaluation) As String ' Dim strSQLInsertCommand As String ' code block Return "whatever" End Function </code></pre> <p></p> <p>It builds (VS2008 sp1) with no errors. I get no response on the android. If I delete the argument 'JSON as OneEvaluation', it will successfully post in a browser and provide a HTML return; but as coded above... the error is: <code> System.InvalidOperationException: AndroidTest Web Service method name is not valid. at System.Web.Services.Protocols.HttpServerProtocol.Initialize() </code></p> <p>FYI, my Android snippet follows:</p> <pre><code>final String URL = "http://www3.myurl.com/JSON/service.asmx/AndroidTest" HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit HttpResponse response; JSONObject json = new JSONObject(); try{ HttpPost post = new HttpPost(URL); json.put("email", email); json.put("password", pwd); StringEntity se = new StringEntity( "OneEvaluation: " + json.toString()); // post.setEntity(se); post.setHeader("Accept", "application/json"); post.setHeader("Content-type", "application/json; charset=utf-8"); // se.setContentEncoding((Header) new BasicHeader(HTTP.CONTENT_TYPE, "application/json; charset=utf-8")); post.setEntity(new ByteArrayEntity(se.toString().getBytes("UTF8"))); // post.setHeader(OneEvaluation, value) // ResponseHandler responseHandler = new BasicResponseHandler(); response = client.execute(post); /* Checking response */ Log.v("TAG", " JSON onItemClick fired! Position:"); if(response!=null){ Log.v("TAG", " Response :" + response.toString()); // Toast.makeText(v.getContext(), response, Toast.LENGTH_LONG); InputStream in = response.getEntity().getContent(); //Get the data in the entity } } catch(Exception e){ e.printStackTrace(); createDialog("Error", "Cannot Estabilish Connection"); Log.v("TAG", " Cannot Estabilish Connection"); } </code></pre> <p>I haven't seen a complete example with both server-side (except those using jQuery) and client side (especially Android). So I hope to save someone else's weekend!</p> <p>I have resisted using C# on the server side, as my other AJAX/JSON services (including those that return JSON) are in vb (and working).</p> <p>I'm asking for help with the server side error... and any suggestions to clean up the Android JSON HTTP_POST.</p> <p>Many Thanks in advance !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload