title: How to set the User-Agent header in SoapHttpClientProtocol?
body: <p>I am calling a 3rd party SOAP service (a Magento webstore) in ASP.NET MVC4.  When importing the web service reference, all of the service methods are automatically implemented by Visual Studio, eg the login soap method is implemented as</p>
  
  <pre><code>    public string login(string username, string apiKey) {
          object[] results = this.Invoke("login", new object[] {
                      username,
                      apiKey});
          return ((string)(results[0]));
      }
  </code></pre>
  
  <p>But when I call this method, <code>this.Invoke</code> sends a POST with this user-agent header automagically added:</p>
  
  <pre><code>User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; 
              MS Web Services Client Protocol 4.0.30319.18444)
  </code></pre>
  
  <p>This header tells the 3rd party that the user agent is IE6.  And many sites automatically block IE6 with a message saying something to the effect of <em>"We do not support IE6.  Go get a real browser and try again"</em></p>
  
  <p>So the soap call breaks but only because the 3rd party site thinks we are using IE6, not because there is anything wrong with the soap call.  If we could change this header to mimic the UA string of a modern web browser then this problem would not exist.</p>
  
  <p>So how then do you change the UA string used by SoapHttpClientProtocol method calls?  It all happens inside of the <code>this.Invoke</code> method, which is part of the .NET core.</p>
  
  <p>EDIT: </p>
  
  <p>The object <code>this</code> in the above autogenerated code above is a subclass of <code>SoapHttpClientProtocol</code>, so yes I could just manually write the user agent in there myself:</p>
  
  <pre><code>    public string login(string username, string apiKey) {
          this.UserAgent = "something, anything except for IE6";
          object[] results = this.Invoke("login", new object[] {
                      username,
                      apiKey});
          return ((string)(results[0]));
      }
  </code></pre>
  
  <p>BUT, this is autogenerated code and will be overwritten anytime the 3rd party updates their service (for Magento it is quite frequently), and I would have to manually add it to every single autogenerated function (a lot of them).  So it's not practical to just write <code>this.UserAgent = "not IE6"</code> here, it needs to be a more useful solution.</p>