WCF服务启用跟踪

时间:2016-06-01 19:28:29

标签: c# asp.net .net web-services wcf

经过两天的尝试和错误以及盲目调试后,我的网络服务在某些情况下仍会产生一些错误,目前我还不知道为什么。 因此,我想启用对服务的跟踪,以便至少得到一些反馈。

但是,我尝试了一些web.config的添加,但是没有一个生成跟踪文件,即使服务响应错误。

这么久,这是我的web.config:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <configSections>
    <section name="entityFramework"        type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
     </configSections>
     <connectionStrings>
     <...removed here... />
     </connectionStrings>
    <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
    <customErrors mode="Off"></customErrors>
    <compilation targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    </system.web>
    <system.serviceModel>
    <services>
      <service name="TimeRecHomePage.Service.TimeService" behaviorConfiguration="TimeServiceBehavior">
        <endpoint name="webHttpBinding" address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" contract="TimeRecHomePage.Service.ITimeService" behaviorConfiguration="webHttp" />
        <endpoint name="mexHttpBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
      </services>
      <bindings>
      <webHttpBinding>
        <binding name="webHttpTransportSecurity">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="TimeServiceBehavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" defaultBodyStyle="WrappedRequest" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" />
  </system.webServer>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      </assemblyBinding>
     </runtime>
     </configuration>

我已经查找了跟踪的配置并测试了web.config的条目,例如{。{3}},here,并且还阅读了here

正如文档中所写,从Windows 8开始,您需要特权才能进行跟踪,我还更改了应用程序池标识,但没有成功(该服务在Win 2012 R2服务器上运行)。 / p>

为了启用和使用跟踪,我缺少什么? 提前感谢您的努力!

1 个答案:

答案 0 :(得分:1)

web.config中需要两个部分,一个是配置了tracelisteners的部分,另一个是system.serviceModel中的诊断部分。

System.Diagnostics程序

添加以下部分:

$("#reservationform").submit(function(e) {
      e.preventDefault();
        var url = document.getElementById('reservationform').action,
            fromDate = document.getElementById('checkin').value,
            toDate = document.getElementById('checkout').value,// the script where you handle the form input.
            dataString = 'fromDate=' + fromDate + '&toDate=' + toDate;
        $.ajax({
            type: "GET",
            url: url,
            data: dataString,
            success: function(name)
            {
                document.getElementById('rooms').innerHTML = name;
            }, 
            complete: function() {
               $("button#check").css("display", "none");
              $("button#book").css("display", "block");
            }
        });
         // avoid to execute the actual submit of the form.

    });

注意use Sonata\AdminBundle\Route\RouteCollection; 的值,并确保在那里添加应用程序标识可以写入的路径。系统范围的临时文件夹应该是一种选择。

system.serviceModel diagniostics

调整您的<system.diagnostics> <sources> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="messages" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\messages.svclog" /> </listeners> </source> <source name="System.ServiceModel" switchValue="Information,ActivityTracing" propagateActivity="true"> <listeners> <add name="tracing" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\temp\tracing.svclog" /> </listeners> </source> </sources> </system.diagnostics> 并添加诊断设置

initializeData

测试您的设置

使用上面的配置,您的日志文件应该被创建,system.serviceModel应该在服务启动时或您为服务请求wsdl时显示条目。它还包含发生的任何异常和堆栈跟踪。