WCF Json GET服务:检查发送方和接收方';端点地址一致
我已经在.NET中工作了一段时间,但我对WCF是新手。我正在尝试使用JSON创建我的第一个WCF服务。我想我会从非常非常简单的开始,然后从那里开始构建。但我不知怎么搞砸了哪怕是最简单的服务。这是我到目前为止得到的 Web.Config:WCF Json GET服务:检查发送方和接收方';端点地址一致,json,wcf,get,endpoint,Json,Wcf,Get,Endpoint,我已经在.NET中工作了一段时间,但我对WCF是新手。我正在尝试使用JSON创建我的第一个WCF服务。我想我会从非常非常简单的开始,然后从那里开始构建。但我不知怎么搞砸了哪怕是最简单的服务。这是我到目前为止得到的 Web.Config: <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /
<?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
{
[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
我得到这个错误:
这封信是写给你的
'http://localhost:10298/MarathonInfoService.svc/GetData"不可能
由于接收端的AddressFilter不匹配,在接收端处理
端点调度器。检查发送方和接收方的
我同意
我能够在调试模式下通过VisualStudio很好地执行服务。但在浏览器中,我只得到了那个错误
我做错了什么
谢谢
Casey如果要创建WCF WebHTTP端点(即返回JSON并使用[WebGet]/[WebInvoke]属性的端点),则该端点需要具有与其关联的
行为
<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>
我也有同样的问题。我有WCF Rest服务项目和Windows主机项目。我需要在上面给出什么?
<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>