我把我的WCF服务抛出后出现错误,出现此错误:如何有效地处理WCF服务与错误处理
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
错误是由使用
throw new FaultException<DatabaseFault>(new DatabaseFault(e.Message));
如何服务抛出我可以如何处理这种情况,而不必每次都重新启动客户端和服务?
我使用WCF 4.0,C#。
编辑1:我使用net.tcp绑定为WCF服务。
编辑2:我想要一个有效的方式来使用WCF。这与John S所说的无关。
编辑3:我的代码有效。但我认为它不像它应该(它被设计的方式)运行。
这是它承载我的服务控制台应用程序:
using (ServiceHost host = new ServiceHost(typeof(AuctionService)))
{
Console.WriteLine("AuctionWCF.TestHost Started");
host.AddServiceEndpoint(
typeof(IAuctionService),
new NetTcpBinding(),
"net.tcp://localhost:9000/AuctionWcfEndPoint");
host.Open();
Console.WriteLine("AuctionWCF.TestHost listens for requests");
Console.ReadLine();
}
这是客户:
AuctionService = new ChannelFactory<IAuctionService>(
new NetTcpBinding(),
new EndpointAddress("net.tcp://localhost:9000/AuctionWcfEndPoint")).CreateChannel();
难道我做错了什么?
的[什么是WCF客户端的最佳解决方法'using'阻止问题?(http://stackoverflow.com/questions/可能重复anothe很好的答案573872 /什么是最好的解决方法为wcf客户端使用块问题) – 2011-12-28 17:51:27
这是如何不高效?另外,我刚刚发现了你确切的问题。你为什么认为不是这样? – 2011-12-28 18:23:49
我不想每次打电话给WCF时打开一个频道。我想每次都使用同一个频道,如果它无法启动另一个频道。我刚开始使用WCF工作,并希望针对此问题提供一些策略 – 2011-12-28 18:28:44