Я только изучаю WCF, пробую разные вещи.
Я установил следующую службу:
[ServiceBehavior(IncludeExceptionDetailInFaults = true,
InstanceContextMode = InstanceContextMode.Single)]
public class TestService : ITestService
{
// This operation is defined as OneWay.
public void Throws()
{
throw new ArgumentException();
}
}
Я использую его в своем клиенте вот так:
var baseAddress = new Uri("net.pipe://localhost/hello");
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(TestService), baseAddress))
{
var netBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
host.AddServiceEndpoint(typeof(ITestService), netBinding, baseAddress);
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
// Create client channel.
var channel = ChannelFactory.CreateChannel(netBinding, new EndpointAddress(baseAddress));
((ICommunicationObject)channel).Open();
try
{
foreach (var i in Enumerable.Range(0, 5000))
{
// channel dies after a few attempts.
channel.Throws();
}
}
Метод Throws определен как IsOneWay = true, что означает, что он не передает обратно клиенту никаких сообщений (, включая ошибки ).
При работе в цикле коммуникационный объект дает сбой после нескольких запусков. Я не могу понять причину этого.
Детали исключения:
System.ServiceModel.CommunicationException: There was an error writing to the pipe: The pipe is being closed. (232, 0xe8). ---> System.IO.PipeException: There was an error writing to the pipe: The pipe is being closed. (232, 0xe8). at System.ServiceModel.Channels.PipeConnection.StartSyncWrite(Byte[] buffer, Int32 offset, Int32 size, Object& holder) at System.ServiceModel.Channels.PipeConnection.Write(Byte[] buffer, Int32 offset, Int32 size, Boolean immediate, TimeSpan timeout, BufferManager bufferManage r) --- End of inner exception stack trace ---
Обратите внимание, что если я изменю тело метода Throws на что-то другое, например Console.WriteLine, все будет работать нормально.
РЕДАКТИРОВАТЬ :Я загрузил пример проекта на свой SkyDrive:http://sdrv.ms/NumUbR
На случай, если кто-то захочет скомпилировать его локально и посмотреть, будет ли он вести себя так же.