When setting up a WCF client and server, how synchronized does the config files must be?

前端 未结 2 723
情深已故
情深已故 2021-02-13 12:09

Most of the WCF examples out there show you how to configure WCF client and server. Now, what happens if you differ the configuration slightly between them? I mean, who has the

2条回答
  •  时光取名叫无心
    2021-02-13 12:42

    In order to address your request in your last comment to my previous answer, I tried to come up with my approach to how I would create (and modify) server- and client-side config's for any given service. This is based on both theory I read (books, blogs), things I've learned in Juval Lowy's WCF Master Class, and quite a bit of practical experience with several large service implementation projects - this isn't available in one single place, on the web or in a book.... so here it goes:

    I would start basically from scratch. Think about your service first:

    • what address does your service live at?
    • what binding(s) do you want to support?

    Simplest scenario: single service, single endpoint, basicHttpBinding, all defaults

    Service config:

    
       
          
             
          
       
    
    

    Corresponding client config:

    
       
          
       
    
    

    Then only ever change something if you really must! And most of all: NEVER EVER let Visual Studio (Add Service Reference) or svcutil.exe screw up your config! Protect it like the apple of your eye!

    Then: if e.g. your data transfer takes more time than the default timeout of 1 minute allows, change that one single setting on both the service side and the client side. Do this by defining a custom binding configuration and referencing that from your endpoints - but change only that - not more! Leave everything else as is, with default values. Don't ever change anything unless you absolutely must (and know what you're doing, and why you're doing it).

    Mind you: the sendTimeout on the client (time allowed until the whole message has been sent) will correspond to the receiveTimeout on the server - the time allowed for the whole message to come in (see this excellent blog post and this MSDN forum thread for more information)

    Service config:

     
        
          
            
          
        
        
          
            
          
        
      
    

    Corresponding client config:

    
       
          
             
          
       
       
          
       
    
    

    As you need other changes, like multiple endpoints on the service side, or local settings like bypassProxyOnLocal - adapt your config, do it carefully, step by step, manually, and consider your config an extremely essential part of your whole service - take care of it, put it in version control etc.

提交回复
热议问题