繁体   English   中英

如何正确配置WCF REST服务终结点?

[英]How to correctly configure a WCF REST service endpoint?

我计划基于不同的合同托管多个RESTful服务。 有很多类似的问题,但是我的web.config文件看起来有所不同,我不知道为什么。

这是我的web.config文件的一部分:

    <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint name="" 
                              helpEnabled="true" 
                              automaticFormatSelectionEnabled="true">
            </standardEndpoint>
          </webHttpEndpoint>
    </standardEndpoints>

这是我在Web应用程序中的服务声明:

    RouteTable.Routes.Add(new ServiceRoute("bob/chocolate", new WebServiceHostFactory(), typeof(RESTchocolate)));
    RouteTable.Routes.Add(new ServiceRoute("bob/vanilla", new WebServiceHostFactory(), typeof(RESTvanilla)));

只有第一个路由似乎可以正常工作(使用.NET的漂亮的“ bob / chocolate / help”端点功能进行测试,以列出可用的方法),这确实并不使我感到惊讶,但是我应该如何修改我的web.config文件? 你们当中有人知道怎么做吗? 我需要修改其他内容吗?

对于那些想知道的人,我的合同是有效的。

如果尝试访问浏览器中的第二个端点,则会在一个不错的.NET屏幕上显示“找不到端点”。

编辑:

我将以下节点添加到我的配置文件中...

    <services>
      <service name="chocolate">
        <endpoint address="bob/chocolate" binding="basicHttpBinding" name="chocolate" contract="RESTapi.IRESTchocolate" />
      </service>
      <service name="vanilla">
        <endpoint address="bob/vanilla" binding="basicHttpBinding" name="vanilla" contract="RESTapi.IRESTvanilla" />
      </service>
    </services>

但是我也有同样的行为。 问题仍然存在

编辑:这是我要求的完整配置文件(没有上面的节点):

    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <authentication mode="None"></authentication>
      </system.web>
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
        </serviceHostingEnvironment>
         <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
          </webHttpEndpoint>
        </standardEndpoints>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>

    </configuration>

我真的建议您安装WCF REST服务模板40并查看引导程序。

Web.config

<standardEndpoints>
  <webHttpEndpoint>
    <!-- 
        Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
        via the attributes on the <standardEndpoint> element below
    -->
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
  </webHttpEndpoint>
</standardEndpoints>

Global.asax

// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM