开发者

Any Change in .NET 4.0 in How to PROPERLY call a WCF Service?

开发者 https://www.devze.com 2023-02-16 00:48 出处:网络
I am asking for some advice (so sorry if this has been asked before): When I call WCF services I use the following pattern. I developed this pattern way back with early WCF releases (in VS2008) and

I am asking for some advice (so sorry if this has been asked before):

When I call WCF services I use the following pattern. I developed this pattern way back with early WCF releases (in VS2008) and am curious now if this Close()/Abort() pattern is still necessary in the current version of WCF (in VS2010). It certainly does work.

I have looked into this and I see many examples calling WCF clients without this pattern, but I also know that many samples on the Internet are inferior. But is it overkill? What's the ideal pattern?

If you do have the answer, it is very important to me that you provide some type of reference so I can research into your suggestion.

  var _Client = new MyServiceReference.MyServiceClient();
  try
  {
      var _Item = _Client.GetItem(123);
      _Client.Close();
      return _Item;
  }
  catch
 开发者_JAVA百科 {
      _Client.Abort();
      throw;
  }


Yes, this is still pretty much the recommended best practice.

See: MSDN Avoiding Problems with the Using Statement

Not much has changed in the way the WCF clients call a service, and how to deal with exceptions and errors.


For consume the WCF Service with avoiding Using approach, I found this wish that help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消