簡単なサービス コントラクトを作成し ( 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 で見つかったトレースが機能しませんでした。新しいアイデアはありますか?