在IIS中托管WCF Atom提要
问题描述:
我有一个我已经生成的简单Atom 1.0提要,类似于the example shown on MSDN。在IIS中托管WCF Atom提要
但是,不是通过控制台应用程序创建主机和测试源,如示例中所示,我尝试通过配置创建端点。
我的配置如下:
<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服务,我能够进入股票说明页面,甚至使用这个地址作为服务引用。但是,如果我尝试调用返回订阅源的方法(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);
}
}
}
答
你(在你的配置通过basicHttpBinding
)混合起来SOAP和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获取大量非常有用且信息丰富的附加资源!