我遵循本指南创建自定义格式程序,因此我可以使用Newtonsoft Json.NET进行对象序列化,因为内置的Microsoft不支持来自父/子的循环关系。WCF WebHttp,服务,行为,端点,自定义Formater
http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx
在他的榜样,他的手工创建他的ServiceHost。我利用路线和本指南向我教授的WebServiceFactory。
http://blogs.msdn.com/b/endpoint/archive/2010/01/06/introducing-wcf-webhttp-services-in-net-4.aspx
从我可以告诉我只需要想出一个办法来适当的行为添加到我的服务端点。任何帮助指引我在正确的方向将不胜感激。
以下为便于参考一些代码片段...
在我的Global.asax
WebServiceHostFactory webServiceHostFactory = new WebServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute(Accounts.Route, webServiceHostFactory, typeof(Accounts)));
如果我的web.config
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<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="false" defaultOutgoingResponseFormat="Json"/>
</webHttpEndpoint>
</standardEndpoints>
在他的节目
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
host.AddServiceEndpoint(typeof(ITestService), new BasicHttpBinding(), "soap");
WebHttpBinding webBinding = new WebHttpBinding();
webBinding.ContentTypeMapper = new MyRawMapper();
host.AddServiceEndpoint(typeof(ITestService), webBinding, "json").Behaviors.Add(new NewtonsoftJsonBehavior());
如果您希望支持REST,那么我肯定会建议您在设计基于REST的SOA时采用新的WCF WebApi框架。在wcf.codeplex.com上找到的新位的扩展点非常好,易于使用。除了WCF团队正在努力解决的一些问题之外,预览版4还是非常出色的。对于JSON.NET支持查看我的帖子在这里:http://wcf.codeplex.com/discussions/255870 – Daniel