IIS 7.5上的WCF Rest服务模板40

时间:2010-08-23 03:25:18

标签: c# wcf iis rest

我正在尝试获取WCF休息服务模板40(CS),它是VS 2010中的在线模板,可部署到Win Server 2008 R2上的IIS 7.5。我们根本没有改变模板,并试图让这个调用工作:

public class Service1
{
    // TODO: Implement the collection resource that will contain the SampleItem instances

    [WebGet(UriTemplate = "")]
    public List<SampleItem> GetCollection()
    {
        // TODO: Replace the current implementation to return a collection of SampleItem instances
        return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
    } ....

我们尝试过:

  • 手动创建.svc文件,因为此模板没有.svc文件。看起来像是:<%@ServiceHost language=c# Debug="true" Service="WcfRestService2.Service1"%>
  • 作为网站发布并将其添加为IIS中的网站。
  • 我们在IIS上安装了.net framework 4.0,并且正在运行。
  • 添加一些webconfig内容以尝试从Global.asax获取端点。
  • 一堆其他东西......

我正在把头发拉过来,抱歉我不能更具体地说明究竟发生了什么。我们遇到的问题是通过IIS无法找到http://localhost/Service1等服务调用,但它们在VS中运行良好。

这是webservice文件:

如何插入xml? http://www.nitricburnstudios.com/Web.config

2 个答案:

答案 0 :(得分:2)

经过多次挫折后终于找到了如何使其发挥作用。

您必须在IIS中启用 HTTP重定向

这可以通过

来完成
  1. 控制面板 - &gt;程序和功能
  2. 打开或关闭Windos功能
  3. 在角色下,添加网络服务器 - &gt;常见的http功能 - &gt; http重定向角色
  4. 此处列出了这种情况:http://blogs.msdn.com/b/rjacobs/archive/2010/06/30/system-web-routing-routetable-not-working-with-iis.aspx

答案 1 :(得分:0)

默认情况下,当你切换到发布到IIS时,它会对vdir而不是网站root进行,所以我猜你需要检查它正在安装的vdir(项目属性,web)并更改url你试图访问http://localhost/WcfRestService1/Service1(或其他)。

当我从模板创建项目时,切换到IIS发布,点击F5,然后点击该网址,我得到预期的输出就好了:

<ArrayOfSampleItem xmlns="http://schemas.datacontract.org/2004/07/WcfRestService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <SampleItem>
    <Id>1</Id> 
    <StringValue>Hello</StringValue> 
  </SampleItem>
</ArrayOfSampleItem>
相关问题