Share via

WCF proxy creation

B M-A 361 Reputation points
2022-07-25T21:14:06.777+00:00

Hello,
I have the client application to consume WCF service

class Test  
{  
    static void Main()  
    {  
        TestService client = new TestService("netTCP");  
  
        // Use the 'client' variable to call operations on the service.  
  
        // Always close the client.  
        client.Close();  
    }  
  
  private void ToDo(string s)  
         {  
           var client = new TestService("netTCP");  
                
         }  
  
}  
  
  

Which is the correct way to create the client ?
When to close the client and when is better to create the proxy?

Developer technologies | .NET | Other
0 comments No comments

Answer accepted by question author

Anonymous
2022-07-26T04:00:17.38+00:00

Hi @B M-A ,

  1. You can create a client in several ways: Service Reference, Svcutil.exe, Channel Factory, Client Base. You may pick and choose what works for you. Here is the example. https://learn.microsoft.com/en-us/dotnet/framework/wcf/wcf-client-overview.
  2. You should close it as recommended. And if you are using async methods, you should close it after the call completes. And remember to add try and catch on close in order to deal with exceptions.

Best Regards,
Jiayao Wu

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.