我正在构建一个应该输出JSON的WCF REST Web服务,但我正在获取XML。
我正在使用ResponseFormat = WebMessageFormat.Json
请帮助我到处搜索,我找不到解决方案。
注意:我甚至尝试过here
中的建议配置文件
<services>
<service name="TestService">
<endpoint address=""
behaviorConfiguration="TestServiceAspNetAjaxBehavior"
binding="webHttpBinding"
bindingConfiguration="webBinding"
contract="TestService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>
答案 0 :(得分:1)
您需要检查的一些事项:
<service>
元素的“name”属性需要与服务类的完全限定名称匹配 - 如果TestService
在命名空间{ {1}},然后必须将服务声明为MyNamespace
- 换句话说,它必须与您在服务的“.svc”文件中的名称相匹配<service name="MyNamespace.TestService">
属性;对于WCF Web端点,您需要让webHttpBinding 和引用一个行为,该行为声明(在您的情况下)behaviorConfiguration
<webHttp />
:WebServiceHostFactory
。有了这个,您不需要在config中定义服务。答案 1 :(得分:0)
我有类似的问题,因为我有这样的标签;
<behavior name="jsonBehavior">
<enableWebScript/>
<webHttp helpEnabled="true"/>
</behavior>
删除后
<webHttp helpEnabled="true"/>
它是固定的。也许这是一个错误。我不确定。