モバイルデバイスを使用してサーバー(vb.net)にデータを投稿しようとしています。 私はクライアント側(Android)について、Encosia articleとsending JSON object with Androidを含むいくつかの偉大な記事を調査しました。vb.net asmx Androidを使用してHTTP-POSTでJSONを受け入れるWebService
私はサンプルクラス作成しました:
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
を、私は私のWebMethod属性を作成しました:
Public Class AsmxCodebehind
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function AndroidTest(ByVal JSON As OneEvaluation) As String '
Dim strSQLInsertCommand As String
' code block
Return "whatever"
End Function
それはエラーなしで(VS2008のSP1)を構築します。私はアンドロイドの応答を取得します。 引数 'JSON as OneEvaluation'を削除すると、ブラウザに正常に投稿され、HTMLの戻り値が返されます。上記のコード化されたとしてではなく...エラーは、次のとおりです。 は System.InvalidOperationException: AndroidTest Web Service method name is not valid. at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
FYI、私のAndroidの抜粋は次のとおりです。
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");
}
は、私が(jQueryのを使用したものを除く)の両方のサーバー側との完全な例を見ていませんクライアント側(特にAndroid)です。だから私は他の誰かの週末を救うことを願っています!
(JSONを返すものも含めて)私の他のAJAX/JSONサービスは、VB(と作業)にあるように私は、サーバー側でC#を使用して抵抗してきました。
私は、サーバー側のエラーで助けを求めています...と任意の提案は、Android JSON HTTP_POSTをクリーンアップします。
多くの方々、ありがとうございます!
私はまだ私がPOSTでJSONを送っていたことを確認するためにバイオリンを使用しました、これはIISで火に取得するために苦労していフィドラーはとして私のポストを示しています。:
POST http://www3.myweb.com/JSON/swUpdate.asmx/SaveProcedureList HTTP/1.1 Accept: application/json Content-type: application/json; charset=utf-8 Content-Length: 44 Host: www3.tidewatertechnology.com Connection: Keep-Alive User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4) Expect: 100-Continue {"OneEvaluation": {"email":"kiddin","password":"no"}}
– SolarBlitz