.NET Adding Custom Http Headers to Web Service Proxy throws errors -


i need attach custom header web service client. purpose created partial class soaphttpclientprotocol class generated when added web reference. however, receiving runtime error when custom headers attached. works fine if custom headers not attached (when comment code attaches headers). if custom headers added receive following error during runtime: client found response content type of 'text/html; charset=utf-8', expected 'text/xml'. ideas?

so here sample code:

 public partial class smartsws : system.web.services.protocols.soaphttpclientprotocol  {     private namevaluecollection _customheaders = new namevaluecollection();      protected override system.net.webrequest getwebrequest(system.uri uri)     {         // add authentication cookie          // object cookiecontainer         smartsivrsecuritymanager.setauthtoken(this);          // set custom headers         setcustomheaders();          httpwebrequest req = (httpwebrequest)base.getwebrequest(uri);         (int = 0; <= _customheaders.count - 1; i++)         {             req.headers.add(_customheaders.keys[i], _customheaders.getvalues(i).getvalue(0).tostring());         }         return req;     }       /// <summary>     /// set custom headers     /// </summary>     /// <param name="smtoken"></param>     public void setcustomheaders()     {         _customheaders.add("version", "1.0");         _customheaders.add("onbehalfof", string.empty);         _customheaders.add("role", "1");         _customheaders.add("endpoint", "001");         _customheaders.add("serviceid", "001");         _customheaders.add("datetime", string.empty);         _customheaders.add("clientapplication", "smartsivrservice");         _customheaders.add("tracewebmethod", "false");         _customheaders.add("clienttouchpoint", "smartsivrservice");         _customheaders.add("channelinfo", "channelinfo");     } } 

when see response of type "text/html", error page trying tell what's wrong. use fiddler or see error page trying tell you.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -