2012-05-26 3 views
6

私は.NETでしばらくの間働いていましたが、私はWCFを初めて使用しています。私はJSONを使って私の最初のWCFサービスを作成しようとしています。私は本当に、本当にシンプルなものから始めると思っていました。しかし、私はどうにかして最も単純なサービスでさえもねつけてしまった。これまでに私が得たことがここにあります。WCF Json GETサービス:送信者と受信者のEndpointAddressが一致することを確認してください

のWeb.Config:次に

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="MarathonInfo.MarathonInfoService"> 
     <endpoint address="http://localhost:10298/MarathonInfoService.svc" binding="webHttpBinding" contract="MarathonInfo.IMarathonInfo" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

、サービス・ファイル内:

namespace MarathonInfo 
{ 
    public class MarathonInfoService : IMarathonInfo 
    { 
     public String GetData() 
     { 
      return "Hello World"; 
     } 
    } 
} 

およびインターフェイスで:だから

namespace MarathonInfo 
{ 
    [ServiceContract] 
    public interface IMarathonInfo 
    { 

     [OperationContract] 
     [WebInvoke(Method = "GET", UriTemplate = "/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] 
     String GetData(); 
    } 
} 

、私はこのURLにアクセスしてください。

http://localhost:10298/MarathonInfoService.svc/GetData 

私はこのエラーを取得する:

The message with To 'http://localhost:10298/MarathonInfoService.svc/GetData' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.

私は、デバッグモードでのVisual Studioによってうまくサービスを実行することができています。しかし、ブラウザでは、私はそのエラーを取得します。

私は間違っていますか?

ありがとうございます!

ケーシー

答えて

15

あなたはWCF WebHTTPエンドポイント(JSONを返し、[のWebGet]/[WebInvoke]属性を使用して、すなわち、1)を作成する場合、エンドポイントは、それに関連付けられた<webHttp/>行動を持っている必要があります。

<system.serviceModel> 
    <services> 
    <service name="MarathonInfo.MarathonInfoService"> 
     <endpoint address="http://localhost:10298/MarathonInfoService.svc" 
       binding="webHttpBinding" 
       contract="MarathonInfo.IMarathonInfo" 
       behaviorConfiguration="Web"/> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
     <behavior> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
     <behavior name="Web"> 
     <webHttp/> 
     </behavior> 
    </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" /> 
</system.serviceModel> 
+2

ありがとうございます!それはトリックでした! – user1418704

+0

本当にうまくいきます。ありがとう。 –

関連する問題