4

簡単なサービス コントラクトを作成し ( IServiceObject)、それを実装しました ( ServiceObject)。ServiceHostコンソール アプリケーション内に含まれるオブジェクトでホストします。メソッドの 1 つの中で、OperationContractを呼び出しますTrace.WriteLine(...)。も呼びますConsole.WriteLine(...)。コンソール アプリケーション内で、 の前後に とOpen()を呼び出しServiceHostます。Trace.WriteLine(...)Console.WriteLine(...)

トレースは autoflush に設定されており、2 つのリスナー (TextWriterTraceListenerおよびConsoleTraceListener) があります。コンソール アプリケーションが起動すると、すべての Trace および ConsoleWriteLine()呼び出しがそれぞれのログに書き込まれます。したがって、Trace 呼び出しはテキスト ファイルとコンソールに書き込み、Console 呼び出しはコンソールに書き込みます。

私のクライアント アプリケーション (別のアプリケーション) がOperationContractメソッドを呼び出すと、そのConsole.WriteLine(...)中の呼び出しだけがコンソール画面に表示されます。呼び出しは、Trace.WriteLine(...)コンソール画面やテキスト ファイルには書き込まれません。

OperationContract(メソッド内から) Trace statsをクエリすると (コンソール画面に出力されますConsole.WriteLine(...))、Trace には 2 つのリスナー (Text と Console) があり、autoflush がオンになっていると言われます。

私の呼び出しがメソッドTrace.WriteLine(...)内からのみリスナーのいずれかに書き込みに失敗する理由を誰かが知っていますか? クラスOperationContractを装飾するために必要な特定の属性はありますか? ServiceObjectどこかに欠けている可能性のある設定はありますか?私のOperationContractメソッド内を除いてどこでも機能するため、トレースは正しく構成されているようです...

これは問題のようです。私の OperationContract とその実装のみを含む私の共有ライブラリ:

IServiceObject.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Diagnostics;

namespace SuccessEHS.Dev.Shared
{
    [ServiceContract]
    public interface IServiceObject
    {
        [OperationContract]
        bool Test(string text);
    }
}

ServiceObject.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.ServiceModel;

namespace SuccessEHS.Dev.Shared
{
    public class ServiceObject : IServiceObject
    {
        public bool Test(string text)
        {
            Console.Write("Testing 1");
            Trace.Write("..2");
            Console.Write("..3");
            Trace.Write("..4");
            Console.WriteLine("..5");

            Console.WriteLine("CW: {0}", text);
            Trace.WriteLine(string.Format("TW: {0}", text));

            return true;
        }
    }
}

Shared.csproj (これが原因だと思われますが、理由はわかりません):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{23F9A333-9CC8-43FA-8A01-06BEA8B9D0E6}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Shared</RootNamespace>
    <AssemblyName>SharedTest</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <PlatformTarget>x86</PlatformTarget>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <CodeAnalysisLogFile>bin\Debug\Shared.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>bin\x86\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <CodeAnalysisLogFile>bin\Release\Shared.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
    <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
    <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

新しい共有ライブラリをホストする新しいサーバー コンソール アプリとそれに接続する新しいクライアント コンソール アプリを作成しましたが、問題はありませんでした。次に、このプロジェクトを共有ライブラリ (上記) としてインポートすると、ServiceObject.cs で見つかったトレースが機能しませんでした。新しいアイデアはありますか?

4

2 に答える 2

1

この記事では、WCF のトレース リスナー/ソースを有効にして構成する方法について説明します。複数のピースがあり、それらのいくつかを見逃すと、トレースが機能しないことが予想されます。

于 2011-11-04T04:34:55.537 に答える
0

WCF Service Trace Viewerを試しましたか。これがあなたに何らかの支援を提供するかどうかを確認してください。

于 2011-11-04T04:38:57.917 に答える