PhoneGap と jQuery Mobile を使用してモバイル アプリケーションを開発しています。私の目的は、クライアント (モバイル) がデータベースに対してクエリを実行できるようにする Web サービスを作成することです。
いくつかの調査の後、AJAX Enabled Services が探していたものである可能性があることがわかりました。そこで、AJAX 対応の WCF サービスを作成することから始め、今のところ、次のメソッドのみを追加しました。
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json)]
public string GetString()
{
return "Hello there";
}
私の web.config は次のようになります。
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebApplication1.MobileServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="WebApplication1.MobileService">
<endpoint address="" behaviorConfiguration="WebApplication1.MobileServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplication1.MobileService" />
</service>
</services>
</system.serviceModel>
</configuration>
このサービスを終了した後、次の方法を使用してクライアントから呼び出しました。
$.ajax({
type: "POST",
url: "http://localhost:11634/MobileService.svc/GetString",
contentType: "application/json",
data: "{}",
dataType: "json",
success: function (result) {
$("#textbox").text(result);
},
error: function (textStatus) {
alert(textStatus);
}
});
サービスを呼び出すと、次のエラーが発生します[object Object]
。私が間違っていることと、正しいテクノロジーを使用しているかどうかについて教えてもらえますか?