2011-07-12 28 views
0

我的服务将被另一个应用程序在同一个盒子上使用(Adobe AIR,因为它发生),我无法运行服务器。我目前正在将WCF服务作为Windows服务运行,以实现此目的。没有服务器意味着没有REST(请纠正我,如果我错了任何这一点),但我仍然希望我的服务能够返回JSON。WCF(dotnet 4)是否需要webHttpBinding才能够轻松返回JSON?

我一直在做这方面的研究,并发现很多人在WebHttpBinding中使用REST服务,然后在配置中设置JSON行为,但出于上述原因,我相信我无法使用REST。

因此,作为背景,我的问题是:作为basicHttpBinding或WSHttpBinding(想要避免由于开销)运行的WCF服务是否可以返回JSON而不必手动滚动它?

如果是这样,有人会解释如何解释吗?

这里是我的app.config当前细节服务

<configuration> 
<system.serviceModel> 
<services> 
    <service name="WcfProjectLibrary.ProjectService"> 
    <endpoint address="" binding="wsHttpBinding" contract="WcfProjectLibrary.IProjectService"> 
     <identity> 
     <dns value="localhost" /> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfProjectLibrary/ProjectService/" /> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>--> 
<behaviors>  
    <serviceBehaviors> 
    <behavior> 
     <!-- To avoid disclosing metadata information, 
     set the value below to false and remove the metadata endpoint above before deployment --> 
     <serviceMetadata httpGetEnabled="True"/> 
     <!-- To receive exception details in faults for debugging purposes, 
     set the value below to true. Set to false before deployment 
     to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="False" />   
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
</system.serviceModel> 
</configuration> 

感谢

回答

1

JSON只能webHttpBinding或退还使用相同的绑定元素为webHttpBinding定义绑定,你仍然可以举办REST(与webHttpBinding)服务在Windows服务。 WebHttpBinding连同WebHttpBehavior负责正确处理非SOAP消息。

我不知道你的意思是没有服务器。在通信方面暴露服务的过程是“服务器”。您只需要完整的.NET Framework 4(客户端配置文件不够)并安装了http.sys(您将需要它与任何基于HTTP的绑定)。

+0

感谢您的回复。我的理解是REST端点只能通过Web服务器传递,而我的WCF服务是作为Windows服务运行的。你已经为我清除了这个,非常感谢你! – sidogg

+0

它在Web服务器上提供了更多功能,因为某些功能与ASP.NET相关,但核心功能仍可以在任何.NET进程中通过自托管提供。 –

+0

这正是我之后的答案,谢谢! – sidogg

相关问题