我已經創造了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