在IIS中托管WCF Atom订阅源

时间:2010-03-17 18:01:05

标签: c# wcf atom-feed

我生成了一个简单的Atom 1.0 Feed,类似于the example shown on MSDN

但是,不是创建主机并通过控制台应用程序测试Feed,而是在示例中,我尝试通过配置创建端点。

我的配置如下:

<system.serviceModel>
        <services>
            <service
                name="MyNamespace.MyService"
                behaviorConfiguration="returnFaults">
                <endpoint
                    address=""
                    binding="basicHttpBinding"
                    contract="MyNamespace.IMyGenericService">
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="returnFaults">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

当我运行WCF服务时,我可以访问股票描述页面,甚至可以使用此地址作为服务参考。但是,如果我尝试调用返回feed(http://localhost:SomeVSPort/MyService/GetFeed)的方法,我会得到一个没有错误的空白页面。在方法中设置断点是不成功的,因为该方法似乎没有被调用。

我的问题是,我应该如何通过IIS公开此托管主机?我应该为我的终端使用不同的配置吗?

作为参考,我的服务声明如下:

namespace MyNamespace
{
    [ServiceContract]
    public interface IMyGenericService
    {
        [OperationContract]
        [WebGet]
        Atom10FeedFormatter GetFeed();
    }

    public class MyService: IMyGenericService
    {
        public Atom10FeedFormatter GetFeed()
        {
            SyndicationFeed feed = new SyndicationFeed();

        //SimpleEntry is a local class that holds location information in a GeoRSS Simple format.
            IList<SimpleEntry> entries = new List<SimpleEntry>()
            {
                new SimpleEntry() { ID = "1", Point = "45.256 -71.92", Title = "Point 1" },
                new SimpleEntry() { ID = "2", Point = "-71.92 45.256", Title = "Point 2" }
            };

            feed.Items = entries
                .Select(e => new SyndicationItem()
                {
                    Content = new XmlSyndicationContent(
                        "application/xml",
                        new SyndicationElementExtension(e)),
                    Title = new TextSyndicationContent(e.Title),
                    Id = e.ID
                });

            return new Atom10FeedFormatter(feed);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您正在混合SOAP(通过配置中的basicHttpBinding)和REST(使用AtomFeedFormatter和操作合同上的[WebGet]属性)。

您需要选择其中一个。既然你想要Atom,我认为你真的想在你的配置中使用webHttpBinding

<system.serviceModel>
    <services>
        <service
            name="MyNamespace.MyService"
            behaviorConfiguration="returnFaults">
            <endpoint
                address=""
                behaviorConfiguration="RESTBehavior"
                binding="webHttpBinding"
                contract="MyNamespace.IMyGenericService">
            </endpoint>
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
           <behavior name="RESTBehavior">
              <webHttp/>
           </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="returnFaults">
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

由于REST没有像WSDL这样的东西,你也可以摆脱任何与MEX相关的东西 - 只是简单的REST。

查看WCF REST Developer Center on MSDN以获取大量非常有用且信息丰富的附加资源!