Asp.net WCF(dotnet 4)是否要求webHttpBinding能够轻松返回JSON?
我的服务将被同一个盒子上的另一个应用程序使用(恰巧是AdobeAIR),我无法运行服务器。我目前正在运行一个WCF服务作为Windows服务,以实现这一点。没有服务器意味着没有休息(如果我有任何错误,请纠正我),但我仍然希望我的服务能够返回JSON 我一直在做这方面的研究,发现很多人使用带有webHttpBinding的REST服务,然后在配置中设置JSON行为,但是出于上述原因,我认为我不能使用REST 因此,作为背景,我的问题是:作为basicHttpBinding或WSHttpBinding运行的WCF服务(由于开销,希望避免)是否可以返回JSON而不必手动滚动 如果是这样的话,有人能解释一下怎么做吗 以下是该服务的my app.config的当前详细信息Asp.net WCF(dotnet 4)是否要求webHttpBinding能够轻松返回JSON?,asp.net,wcf,air,wcf-binding,Asp.net,Wcf,Air,Wcf Binding,我的服务将被同一个盒子上的另一个应用程序使用(恰巧是AdobeAIR),我无法运行服务器。我目前正在运行一个WCF服务作为Windows服务,以实现这一点。没有服务器意味着没有休息(如果我有任何错误,请纠正我),但我仍然希望我的服务能够返回JSON 我一直在做这方面的研究,发现很多人使用带有webHttpBinding的REST服务,然后在配置中设置JSON行为,但是出于上述原因,我认为我不能使用REST 因此,作为背景,我的问题是:作为basicHttpBinding或WSHttpBindin
<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>
谢谢只有使用
webHttpBinding
或使用与webHttpBinding
相同的绑定元素的自定义绑定才能返回JSON,并且您仍然可以在windows服务中承载REST(使用webHttpBinding
)服务WebHttpBinding
与WebHttpBehavior
一起负责正确处理非SOAP消息
我不知道你说没有服务器是什么意思。就通信而言,公开服务的进程是“服务器”。您只需要安装完整的.NET framework 4(客户端配置文件不够)和http.sys(您需要它与任何基于http的绑定一起使用)。感谢您的回复。我的理解是REST端点只能通过web服务器交付,而我的WCF服务是作为Windows服务运行的。你为我澄清了这件事,非常感谢!它在web服务器上提供了更多功能,因为某些功能与ASP.NET相关,但核心功能仍然可以在任何.NET进程中通过自托管提供。我无法访问REST端点,我已编辑了我的问题以显示我当前的app.config。我没有svc文件,因为WCF项目没有为我创建svc文件。我是否需要自己创建它才能拥有一个可联系的端点?您说过您不想在web服务器上托管它,但您的服务正在测试web服务器上运行,您显然是在为web服务器托管而开发它。否,我已将此服务作为windows服务安装。我可以浏览到指定为基址的端点(默认为SOAP),我的测试客户机可以有效地使用服务。我正在使用installutil安装服务。我和你一样惊讶,这在Windows服务中起作用。