我已经创造了IIS和WCF客户举办了简单的WCF服务,并想通了,当u赶上从WCF服务的FaultException,然后调用客户端后,不释放会议。中止()释放会话(如微软样本所述),它不释放会话并在第11次呼叫挂断。中止()WCF客户端代理的方法捕获的FaultException
这里是例子:
WCF服务:
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
public class Service1 : IService1
{
public string GetData(int value)
{
throw new FaultException("Exception is here");
return string.Format("You entered: {0}", value);
}
}
客户:
class Program
{
static void Main(string[] args)
{
Service1Client client = null;
for(int i = 0; i < 15; i++)
{
try
{
client = new Service1Client();
client.GetData(100);
}
catch (TimeoutException timeoutEx)
{
Console.WriteLine(timeoutEx);
client.Abort();
}
catch (FaultException faultEx)
{
Console.WriteLine(faultEx);
client.Abort();
}
catch (CommunicationException commEx)
{
Console.WriteLine(commEx);
client.Abort();
}
}
}
}
但是如果你client.Close更换client.Abort() ()for catch(FaultException),那么所有东西都像魅力一样,在第11次调用wcf后没有锁定 - 服务方法。
为什么会这样?为什么在FaultException被捕获后Abort()方法不会清理会话?
你刚才复制的粘贴在这里呢? http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/f86c056a-4027-453a-a46c-fc223e03589b/ – oleksii 2011-05-04 17:16:33