2016-05-20 4 views
1

を返します。呼び出すWCFサービスメソッドは、これは私のjQueryのAJAXの方法である404

<client> 
    <endpoint address="http://localhost:56537/DemoService1.svc" binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IDemoService1" contract="DemoService.IDemoService1" 
    name="BasicHttpBinding_IDemoService1" /> 
</client> 
<behaviors> 
    <serviceBehaviors> 
     <behavior name="ServiceBehaviour"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
     <behavior name="EndBehaviour"> 
      <webHttp/> 
     </behavior> 
    </endpointBehaviors> 
</behaviors> 
<services> 
     <service behaviorConfiguration="ServiceBehaviour" name="DemoService"> 
      <endpoint address="" binding="webHttpBinding" contract="IDemoService1" behaviorConfiguration="EndBehaviour"></endpoint> 
     </service> 
    </services> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

ソリューションを提供してください:

[OperationContract] 
[WebInvoke(UriTemplate = "/IsEmailAvailable", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] 
bool IsEmailAvailable(string Email); 

私のWebConfigは、次のようになります。私はjQueryの新機能です。

答えて

0

問題は、あなたのAJAX呼び出しのURLであるように見えます:あなたはチルダ(〜)文字でURLを始めている

url:"~/DemoService1.svc/IsEmailAvailable", 

注意してください。チルダは、 "Application Root"を意味するASP.NETトークンです。 JQueryはこれが何を意味するのかわからないので、ajaxコールはおそらく有効なURLではない "http://mysite/~/DemoService1.svc/IsEmailAvailable"のようなものになります。

urlパラメータを有効なURLに置き換えると、404が消えてしまう可能性があります。これをトラブルシューティングするのに適したツールは、ブラウザまたはFiddlerのデベロッパーコンソールです。私は、クライアント側の呼び出しが正しく機能しない理由をトラブルシューティングする際に、非常に貴重なものであることを発見しました(信頼してください...あなたはたくさんのHTTP応答コードを扱うつもりです。例外の詳細)。

関連する問題