c# - Calling Soap web service over HTTP giving exception "Connection close" -


i calling third party web service on http failing connect in wpf application/console application. exception connection close. wondering why closed though same soap message works in soap ui. can give action urn copyed soap ui. please suggest wrong. since not using browser cros domain problem should not be.

my c# code follows.

using system; using system.collections.generic; using system.io; using system.linq; using system.net; using system.text; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; using system.xml;  namespace ctwpfapp {     /// <summary>     /// interaction logic mainwindow.xaml     /// </summary>     public partial class mainwindow : window     {         public mainwindow()         {             initializecomponent();         }          private void button_click(object sender, routedeventargs e)         {             callwebservice();         }         public static void callwebservice()         {             var _url = "https://myservice.com/webservices/ct/services/4.1";             var _action = "urn:provider/interface/ctservices/getcpninstances";              xmldocument soapenvelopexml = createsoapenvelope();             httpwebrequest webrequest = createwebrequest(_url, _action);             insertsoapenvelopeintowebrequest(soapenvelopexml, webrequest);              // start asynchronous operation response             webrequest.begingetresponse(new asynccallback(getresponsecallback), webrequest);         }          private static void getresponsecallback(iasyncresult asynchronousresult)         {             httpwebrequest request = (httpwebrequest)asynchronousresult.asyncstate;              // end operation /* i'm getting exception connection close."*/             httpwebresponse response = (httpwebresponse)request.endgetresponse(asynchronousresult);              stream streamresponse = response.getresponsestream();             streamreader streamread = new streamreader(streamresponse);             string responsestring = streamread.readtoend();             console.writeline(responsestring);             // close stream object             streamresponse.close();             streamread.close();              // release httpwebresponse             response.close();                    }          private static httpwebrequest createwebrequest(string url, string action)         {             httpwebrequest webrequest = (httpwebrequest)webrequest.create(url);             webrequest.headers.add("soapaction", action);             webrequest.contenttype = "text/xml;charset=\"utf-8\"";             webrequest.accept = "text/xml";             webrequest.method = "post";             webrequest.keepalive = false;             webrequest.timeout = 300000;             return webrequest;         }          private static xmldocument createsoapenvelope()         {             xmldocument soapenvelop = new xmldocument();             soapenvelop.loadxml(@"<soap-env:envelope xmlns:soap-env=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ns1=""urn:dictionary:com.ct.webservices""><soap-env:header xmlns:wsse=""http://docs.myses.org/wss/2004/01/200401-wss-wssecurity-secext-1.0.xsd""><wsse:security soap-env:mustunderstand=""1""><wsse:usernametoken><wsse:username>fiwjiueji</wsse:username><wsse:password type=""http://docs.myses.org/wss/2004/01/200401-wss-username-token-profile-1.0#passwordtext"">tjrrfrsi</wsse:password></wsse:usernametoken></wsse:security></soap-env:header><soap-env:body><ns1:getcpninstances></ns1:getcpninstances></soap-env:body></soap-env:envelope>");             return soapenvelop;         }          private static void insertsoapenvelopeintowebrequest(xmldocument soapenvelopexml, httpwebrequest webrequest)         {             using (stream stream = webrequest.getrequeststream())             {                 soapenvelopexml.save(stream);             }         }     } } 

take out webrequest.keepalive = false in createwebrequest method.

when using http/1.1, keep-alive on default. setting keepalive false may result in sending connection: close header server. -from http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.keepalive.aspx


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -