私は奇妙な状況に直面しています。 私は理解していないかもしれませんが、私は明確化が必要です。同じインスタンスの2つのメソッドを呼び出すと、WCFのDisposeメソッドが呼び出されます
私はWCFを使用していくつかの印刷物をしています。 以下は、問題を提示するためにできるだけ小さなコードスニペットです。
WCFサービス
[ServiceContract]
public interface IPrintLabelService
{
[OperationContract]
bool Generate(string templateFullFilename, Dictionary<string, string> textFields, Dictionary<string, string> imageFields);
[OperationContract]
bool Print(string printerName);
}
public class PrintLabelService : IPrintLabelService, IDisposable
{
private WordWrapper _wordWrapper;
public PrintLabelService()
{
_wordWrapper = new WordWrapper();
}
public bool Generate(string templateFullFilename, Dictionary<string, string> textFields, Dictionary<string, string> imageFields)
{
return _wordWrapper.Generate(textFields, imageFields);
}
public bool Print(string printerName)
{
return _wordWrapper.PrintDocument(printerName);
}
public void Dispose()
{
if (_wordWrapper != null)
{
_wordWrapper.Dispose();
}
}
}
ユニットテスト
public void PrintLabelTestMethod()
{
ILabel label = null;
try
{
//some stuff
// ...
// Act
label.Generate();
label.Print(printerName);
}
finally
{
label.Dispose();
}
}
ラベルクラス
class Label : ILabel
{
private readonly PrintLabelServiceClient _service;
private bool _disposed = false;
public Label(string templateFullFileName)
{
_service = new PrintLabelServiceClient();
}
public bool Generate()
{
return _service.Generate(TemplateFullFileName, textFields, imageFields);
}
public bool Print(string printerName)
{
return _service.Print(printer.Name);
}
}
ときCALリン(ユニットテスト部)
label.Generate();
、次いで
label.Print(printerName);
サービスでdisposeメソッドを(上記呼のそれぞれについて)を2回呼び出されます。そして、_wordWrapperが再初期化され、その状態が損なわれています。
それぞれの呼び出しに対してdisposeが呼び出され、なぜDisposeが2回呼び出されないようにするには?
どのバインディングを使用しますか? 'basicHttpBinding'? – user1429080
はい、これは私が使用しているものです – ehh