私はしばらくの間.NETで作業してきましたが、WCFは初めてです。JSONを使用して最初のWCFサービスを作成しようとしています。本当に、本当にシンプルに始めて、そこから構築しようと思いました。しかし、私はどういうわけか、最も単純なサービスでさえも台無しにすることができました。これが私がこれまでに得たものです。
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
このエラーが発生します:
EndpointDispatcherでのAddressFilterの不一致が原因で、To'http:// localhost:10298 / MarathonInfoService.svc/GetData'のメッセージを受信者で処理できません。送信者と受信者のEndpointAddressesが一致していることを確認します。
VisualStudioをデバッグモードで使用してサービスを正常に実行できます。しかし、ブラウザでは、そのエラーしか表示されません。
私は何が間違っているのですか?
ありがとう!
ケーシー