gpt4 book ai didi

json - WCF Json GET服务: Check that the sender and receiver's EndpointAddresses agree

转载 作者:行者123 更新时间:2023-12-04 13:24:06 24 4
gpt4 key购买 nike

我已经在.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();
}
}

因此,当我转到该网址时:
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.



我可以在 Debug模式下通过Visual Studio很好地执行服务。但是在浏览器中,我只会收到该错误。

我究竟做错了什么?

谢谢!

凯西

最佳答案

如果要创建WCF WebHTTP端点(即返回JSON并使用[WebGet]/[WebInvoke]属性的端点),则该端点需要具有关联的<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>

关于json - WCF Json GET服务: Check that the sender and receiver's EndpointAddresses agree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10764348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com