私は何時間も探し回り、これを機能させるためにさまざまなことを試みてきました。私はスタックオーバーフローに関する非常に多くの記事を試しましたが、私はあまりにも愚かで物事を機能させることができないか、または私が喜びを体験するのを妨げているいくつかのユニークで奇妙な構成を持っています.
このチュートリアルで概説されている WCF サービスを作成します。
http://www.codeproject.com/Articles/97204/Implementing-a-Basic-Hello-World-WCF-Service
これは非常に基本的で、メソッドが 1 つあり、必要なのは、json を使用して jQuery.AJAX() で使用できるようにすることだけです。
IIS でホストしていますが、動作します。問題なく WSDL にアクセスできます。
次のコードでそれを消費しようとします:
$.ajax({
    dataType: 'json',
    type: 'POST',
    contentType: "application/json",
    url: "//localhost:546/HelloWorldService.svc/GetMessage",
    data: {
        name: "Joe"
    }
    }).done(function(msg){
        console.log(msg);
        $("#result").append(msg);
});
私はいつもエラーが発生します。私が試したことに基づいて、500エラー、402エラー、不適切なコンテンツに関するエラー...すべてのエラーが発生します。
以下の記事の解決策を実装してみました。それらは、web.configエンドポイントを変更することから(変更する必要があることはわかっていますが、JSONエンドポイントを追加するという点でこれまでに試したことはありません)、次のようなものを追加することまでさまざまです。
[WebInvoke(Method = "POST", UriTemplate = "json/PostSalesOrderData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
インターフェイスに。
これは、私が見て、私のソリューションに衝突して機能させようとしたが、あまり成功しなかった記事の一部です。
Phonegap Android の Javascript JSON および WCF Web サービス
JSON、JSONP、および SOAP エンドポイントを使用した WCF サービス
2 つのエンドポイント (soap、json) と 1 つのサービス メソッド
.Net 4でWCF RESTサービスがJSONを受け入れない
私もこのチュートリアルを読み、彼が言わなければならなかったことを使用して、私のソリューションを機能させようとしました. まだ何も!
http://www.primordialcode.com/blog/post/passing-json-serialized-objects-wcf-service-jquery
これが私のインターフェースの外観です
[ServiceContract]
public interface IHelloWorldService
{
    [OperationContract]
    [WebInvoke(UriTemplate = "GetMessage", Method = "POST",
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json)]
    String GetMessage(String name);
}
私が喜びを経験するのを手伝ってくれる人はいますか?
私の質問を見てくれてありがとう。さらに情報が必要な場合、または十分な情報が提供されていない場合はお知らせください。
私は愚かな何かを逃しているに違いない...私はそれがそれほど難しいことではないことを知っています。
編集:
Web.Config の作業
<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebHTTPEndpointBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MyServiceTypeBehaviors">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="MyWebServiceBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
      </webHttpBinding>
    </bindings>
    <services>
      <service name="MyWCFServices.HelloWorldService"
       behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="MyWebServiceBinding" behaviorConfiguration="WebHTTPEndpointBehavior"
          contract="MyWCFServices.IHelloWorldService"/>
        <endpoint contract="IMetadataExchange"
          binding="mexHttpBinding" address="mex"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>