2015-06-29 86 views
0

服務合同信息低於 服務合同:WCF Rest服務未返回JSON數據。但是,它適用於XML

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

這裏的配置細節 配置:

<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"/>  

當我調試,GetCustomData()返回列表。但是當我檢查瀏覽器返回沒有..沒有錯誤信息。請幫我

+0

如果我改變ResponseFormat = WebMessageFormat.Xml ,它適用於Xml \ – Raj

回答

0

請配置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