English 中文(简体)
WCF Json Get Service: 检查发件人和接收人是否同意
原标题:WCF Json GET Service: Check that the sender and receiver s EndpointAddresses agree

我已经在.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

我知道这个错误:

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.

我可以在调试模式下通过视觉工作室很好地执行这项服务。但在浏览器中,我只能得到这个错误。

我做错什么了?

谢谢!

凯西

最佳回答

如果您想要创建 WCF WebHTTP 端点( 即返回 JSON 并使用 [WebGet] / [WebInvoke] 属性的端点), 端点需要具备 < code\lt;webHtp/> 行为的相关特性 。

<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 DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

Access WCF service on same server

I have a .NET website with a WCF service. How do I access the current operations context of my service? One possible work around is to just make a call to the service within the app...but that seems ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

The service operation requires a transaction to be flowed

I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods). We have common 3 tier architecture. DAL (WCF) BLL Web ...

热门标签