2011-07-12 63 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

相關問題