简体   繁体   English

WCF Rest Service不返回JSON数据。 但它适用于XML

[英]WCF Rest Service is not returning JSON data. But It works for XML

The service contract info is below Service Contract: 服务合同信息位于服务合同下方:

 [OperationContract]
    [FaultContract(typeof(DcCustomFaultMessage))]        
    [WebInvoke(Method="GET", ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "/GetCustomData")]
    List<DcCustomData> GetCustomData();

and the config details here Config: 和配置详细信息在这里配置:

<system.serviceModel>
<services>
  <service name="MyService" behaviorConfiguration="MyServiceBehavior">
    <endpoint address="" binding="webHttpBinding"  bindingConfiguration="MyServiceBinding" behaviorConfiguration="web" contract="IMyService"/>
  </service>     
</services>    
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="True"/>
      <serviceTimeouts transactionTimeout="05:00:00"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
      <serviceMetadata httpGetEnabled="True"/>      
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web" >
      <webHttp helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json" />
    </behavior>
  </endpointBehaviors>
</behaviors>
<standardEndpoints>
  <webHttpEndpoint>
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat="Json"/>
  </webHttpEndpoint>
</standardEndpoints>  
<bindings>
  <webHttpBinding>
    <binding name="MyServiceBinding">
      <security mode="None"/>
    </binding>
  </webHttpBinding>
</bindings>    
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />    
<diagnostics performanceCounters="All"/>    

When i debugged ,GetCustomData() returns list. 当我调试时,GetCustomData()返回列表。 but when i check it on browser returns nothing.. no error information. 但是当我在浏览器上检查它时,什么也没有返回。 please help me 请帮我

Please configure WCF Message logging and use svctraceviewer tool to see the actual error that probably is happening behind the scenes: 请配置WCF消息日志记录,并使用svctraceviewer工具查看可能在幕后发生的实际错误:

<configuration>
<system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="wcfTraceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="E:\Errors\WcfTrace.svclog" traceOutputOptions="DateTime" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
 </configuration>

https://msdn.microsoft.com/en-us/library/ms731859%28v=vs.110%29.aspx https://msdn.microsoft.com/zh-CN/library/ms731859%28v=vs.110%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM