0

WebOS タブレットで使用されている JavaScript を介して、ローカル ネットワーク上の Web サービス ページにコマンドを送信しようとしています。問題は、私がこれまでにこれをやったことがなく、そもそもそれが可能かどうか疑問に思っていたことです? VB.net を作成して、Web サービスの呼び出しや Web ページをリッスンすることはできますか?

Dreamweaver を使用して phonegap から「アプリ」を作成します。アプリで押すボタンに応じて必要に応じてタスクを実行するために、JavaScript を使用して PC 上で常に読み取ることができる文字列を Web サービスに送信する例を探しています。

例として:

 WebOS app > 
 button pushed in app to call up Internet Explorer > 
 sends "IE" string to WS > 
 WS triggers the correct exec to start depending on the string sent to it (IE) > 
 WS sends back "OK" to WebOS app when program is launched

誰かがこのような例を持っていますか?

更新 だから私は私のjavascriptでそのようなことをしますか?:

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">

function buttonClicked(str what2Pass)
{
  $.ajax({
    async : false, /* set as true if you want asynchronous behavior */
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "http://localhost:7777/WebService.asmx/PerformAction",
    data: { "webOSCommand" : what2Pass},
    dataType: "json",
    success: function(data){
        alert(true);
    }
  });
}

<html>
<body>
<input type="button" id="button1" value="run IE on PC" onClick="buttonClicked('IE');" />
</body>
</html>

私のWSの場合は次のようになります。

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Diagnostics
Imports System.Web.Script.Services

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<ScriptService()> _
Public Class Service
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function PerformAction(byRef webOSCommand as String) As String
        Dim oPro As New Process

        With oPro
            .StartInfo.UseShellExecute = True
            .StartInfo.Arguments = "http://www.google.com"
            .StartInfo.FileName = "internet explorer.exe"
            .Start()
        End With

        Return "Started"
    End Function

End Class
4

2 に答える 2

1

はい、ajax を介して Javascript から Web サービスを呼び出すことができます。一例はこれです:

$.ajax({
  type: "POST",
  contentType: "application/json; charset=utf-8",
  url: "WebService.asmx/PerformAction",
  data: { "somestring" : "IE"},
  dataType: "json"
});

あなたのウェブサービス:

[WebMethod]
 //parameter name must match the parameter name passed in from the Ajax call (sometring)
 public static string PerformAction(string somestring) 
 {
   return "something";
 }

詳細な例はこちら。

于 2012-07-23T15:53:40.923 に答える
1

あなたがしていることは正しいですが、[ScriptService] 属性で Web サービス クラスを装飾する必要があります。

[ScriptService]
  public class MyWebService : WebService {
   [WebMethod]
   public void MyMethod() {
   }
}

これが完了すると、これまでと同様に $.ajax を介して Web サービスにアクセスできます。

アップデート

JavaScript 関数にわずかな変更を加えます。「done」メソッドを使用する代わりに、$.ajax メソッドに渡される設定オブジェクトの「success」プロパティを設定しています。Web サービスの呼び出しを非同期にする場合は、次のコードに示すように async プロパティを設定できます。

function buttonClicked(str what2Pass)
{
  $.ajax({
    async : false, /* set as true if you want asynchronous behavior */
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "http://localhost:7777/WebService.asmx/PerformAction",
    data: { "webOSCommand" : what2Pass},
   dataType: "json",
   success: function(data){
    alert(data);
   }
   });
}
于 2012-07-23T16:38:37.417 に答える