2016-12-21 18 views
1

私は、私が作成したWCF WebServiceを呼び出すためのjavascriptとAjax POSTを備えた単純なHTMLページを持っています。C#WCF WebサービスへのAjax POST、404が見つかりません

HTMLページは、ユーザー入力からすべての情報を収集し、jsonでラップし、Webサービスを呼び出す必要があります。

WebサービスはAjax POSTを受け取り、jsonをオブジェクトに逆シリアル化してDBに挿入します。

localhost IISサーバーでWCFサービスを公開しましたが、エラー404が表示されません。また、同じWebサイトの下にある同じアプリケーションで、同じIISローカルホストでHTMLページをホストしています。

何が問題なのですか?私はこの問題を2日間解決していきたいと思っています。

だからこれは私のコードです:

Ajaxのポスト:

 $.ajax({ 
        type: 'POST', 
        crossDomain: true, 
        dataType: 'json', 
        url: "http://localhost/wcf_test/Service1/InsertUpdateIndividualEpxert", 
        data: JSON.stringify({individualExpert}), 
        contentType: "application/json; charset=utf-8", 
        success: onDataReceived, 
        error: onDataError 
      }); 

function onDataReceived(data) 
{ 
    console.log('Everything is good!'); 
} 
function onDataError() 
{ 
    console.log('Not working mister!'); 
} 

WCFインタフェース:

 [OperationContract] 
    [WebInvoke(Method = "POST", 
     RequestFormat = WebMessageFormat.Json, 
     ResponseFormat = WebMessageFormat.Json, 
     BodyStyle = WebMessageBodyStyle.Bare, 
     UriTemplate = "InsertUpdateIndividualEpxert/{json}")] 
    void InsertUpdateIndividualEpxert(string json); 

WCFのWeb.Config:

<system.serviceModel> 
<bindings> 
    <webHttpBinding> 
    <binding name="Service1_HttpBinding"> 
    </binding> 
    </webHttpBinding> 
</bindings> 

<behaviors> 
    <endpointBehaviors> 
    <behavior name="Service1_EndpointBehavior"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="Service1_ServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<services> 
    <service behaviorConfiguration="Service1_ServiceBehavior" name="WS_Experts.Service1"> 
    <endpoint address="" 
     behaviorConfiguration="Service1_EndpointBehavior" 
     binding="webHttpBinding" 
     bindingConfiguration="Service1_HttpBinding" 
     contract="WS_Experts.IService1" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 

答えて

0

だから私はちょうど持っていました2つの問題。

サービスインタフェースで
  1. UriTemplateは "InsertUpdateIndividualEpxert" されているべきであり、NOT "InsertUpdateIndividualEpxert/{JSON}"

  2. Iは "Epxert" を書いたの代わりに"エキスパート"私はこのアウトを把握するために使用さ

ツールは、Google Chromeの「ポストマン」た(ちょうどフルスペックを与え、何を宣伝しない)、私が「エンドポイントが見つかりません」という理解できるエラーを与えました...その瞬間、私はどこを台無しにしたのか分かりました!

今は「405メソッドが許可されていません」が表示されますが、私の友人は別のボールゲームです!

ハッピーコーディングの皆さん!

関連する問題