【问题标题】:WCF RESTFul Service - 404 with endpoint not found with 2 servicesWCF RESTFul 服务 - 404 与 2 个服务未找到端点
【发布时间】:2012-04-09 08:47:16
【问题描述】:

我有两个 WCF 服务 Exchange1.svc 和 Exchange2.svc 都设置为 RESTful JSON 消耗品。 Exchange1.svc 工作正常,但当我尝试发布到 Exchange2.svc 时,我收到 Endpoint not found 消息。

我做错了什么?

我的 IExchange2 接口是:

[ServiceContract]
public interface IExchange2
{
    [System.ServiceModel.OperationContract(Name = "InsertReading")]
    [WebInvoke(UriTemplate = "/InsertReading?memberID={memberID}", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
    void InsertReading(string memberID);
}

我要访问的网址是:http://localhost:49701/Exchange2.svc/DiaInsertReading?memberID=6519548

我的配置是:

<system.serviceModel>
<behaviors>
    <endpointBehaviors>
        <behavior name="MyNamespace.Exchange1Behavior">
            <webHttp/>
        </behavior>
        <behavior name="MyNamespace.Exchange2Behavior">
            <webHttp/>
        </behavior>             
    </endpointBehaviors>
</behaviors>
<services>
    <service name="MyNamespace.Exchange1">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="MyNamespace.Exchange1Behavior" contract="MyNamespace.IExchange1" />
    </service>
    <service name="MyNamespace.Exchange2">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="MyNamespace.Exchange2Behavior" contract="MyNamespace.IExchange2" />
    </service></services></system.serviceModel>

【问题讨论】:

  • 刚刚错过了我现在在原帖中更新的部分网址...

标签: c# wcf web-services rest


【解决方案1】:

我已经编辑了我的帖子,因为答案没有帮助。由于您使用 svc 在 IIS 中托管,因此您不需要像我在之前的回答中所说的那样在绑定中设置地址。基地址将是您服务器的位置。例如:http://localhost:49701/Exchange2.svc。如果您点击此地址,您应该会访问 WCF 服务网页。

由于您使用的是 POST 方法,您可以在请求正文中发送数据。如果您安装了提琴手,则在作曲家中,您可以将发布方法和地址设置为http://localhost:49701/Exchange2.svc/InsertReading,如果这是您的服务地址。 在请求正文的正文中,您设置 { memberID:"123" } 将 123 更改为您想要发送到您的服务的任何值。

或者您可以发送地址中的数据,例如:http://localhost:49701/Exchange2.svc/InsertReading?memberID=123

如果您现在执行您的请求,它应该返回响应 200 OK。

【讨论】:

  • 感谢 Bassetassen 的更新 - 我也会尝试一下。
【解决方案2】:

web.config 文件中指定您的端点

<service name="MyNamespace.Exchange2">
<endpoint address="Exchange2" binding="webHttpBinding" behaviorConfiguration="MyNamespace.Exchange2Behavior" contract="MyNamespace.IExchange2" />

然后,将此端点添加到您的 URL 中:

http://localhost:49071/Exchange2/DiaInsertReading?memberID=6519548

【讨论】:

  • 我按照 Bassetassen 的说明添加了端点,但它仍然不起作用。
猜你喜欢
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-15
  • 1970-01-01
  • 2015-04-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多