473,383 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to keep connection alive when using webrequest?

string strURL = (Request.IsSecureConnection ? "https://website.com/Transaction.asmx" : "http://website.com/wTransaction.asmx");

string strCommand = clsMisc.strGetDataFromPage(this, "c", "", PostMethod.BOTH);
string strAppCode = clsMisc.strGetDataFromPage(this, "a", "WEBIN", PostMethod.BOTH);
string strVenueCode = clsMisc.strGetDataFromPage(this, "v", "", PostMethod.BOTH);
long transcationid= long.Parse(clsMisc.strGetDataFromPage(this, "t", "0", PostMethod.BOTH));
string strParam1 = clsMisc.strGetDataFromPage(this, "p1", "", PostMethod.BOTH);
string strParam2 = clsMisc.strGetDataFromPage(this, "p2", "", PostMethod.BOTH);
string strParam3 = clsMisc.strGetDataFromPage(this, "p3", "", PostMethod.BOTH);
string strParam4 = clsMisc.strGetDataFromPage(this, "p4", "", PostMethod.BOTH);

StringBuilder sbrPost = new StringBuilder();

string strIPAddress = Request.UserHostAddress.ToString();
if (Request.Headers.ToString().Contains("&X-Forwarded-For="))
{
strIPAddress = Request.Headers["X-Forwarded-For"].ToString();
}
strAppCode = "|APPCODE=" + strAppCode + "|IPADDRESS=" + strIPAddress + "|";

//strAppCode = "|APPCODE=" + strAppCode + "|IPADDRESS=" + Request.UserHostAddress.ToString() + "|";

sbrPost.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sbrPost.Append("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"><soap12:Body><objExecute xmlns=\"http://www.website.com/\">");
sbrPost.Append("<strAppCode>" + strAppCode + "</strAppCode>");
sbrPost.Append("<lngTransactionIdentifier>" + lngTransId + "</lngTransactionIdentifier>");
sbrPost.Append("<strCommand>" + strCommand + "</strCommand>");
sbrPost.Append("<strParam1>" + strParam1 + "</strParam1>");
sbrPost.Append("<strParam2>" + strParam2 + "</strParam2>");
sbrPost.Append("<strParam3>" + strParam3 + "</strParam3>");
sbrPost.Append("<strParam4>" + strParam4 + "</strParam4>");
</objExecute></soap12:Body></soap12:Envelope>");
string strPost = sbrPost.ToString();

WebRequest objReq = WebRequest.Create(strURL);
WebResponse objRes;
StreamReader smrRes;

byte[] bytData = Encoding.UTF8.GetBytes(strPost);
objReq.Method = "POST";
objReq.ContentType = "application/soap+xml";
objReq.ContentLength = bytData.Length;
objReq.Timeout = 600000; // 10 minutes
Stream objPost = objReq.GetRequestStream();
objPost.Write(bytData, 0, bytData.Length);
objPost.Close();
objRes = objReq.GetResponse();
smrRes = new StreamReader(objRes.GetResponseStream());
Response.Write(smrRes.ReadToEnd());
Response.ContentType = "text/xml";
smrRes.Close();
Response.End();
}
catch (Exception err)
{
clsLog.blnLogError(strErrorPage,strErrorMethod, "",err.Message);
}
}


I get an error on da line objPost.Close();.....the unusual error is that when I debug this code line by line slowly using F10 in visual studio 2010...the code works..but when I just run the program or even debug the program fast...it throws an error at that line.. it gives an error that the connection which was expected to be open was closed by the server..

HELLLLPPP!!!
Mar 8 '11 #1
0 1520

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sean Erwin | last post by:
I am having a very frustrating intermittent problem. I am making an A2A call to a remote server and when I issue the: WebRequest.getResponse call it occasionally fails with the following error: ...
0
by: John | last post by:
Hi I am using the Internet Transfer Control as follows; strData = "Some data" strHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrLf objInet.Execute strURL, "POST",...
0
by: John | last post by:
Hi I am trying to use the internet transfer control to send some data to a site. I want my MS ISA proxy server to keep the connection alive. What syntax should I use to send the 'keep alive'...
1
by: GrantS | last post by:
I am unable to get the connection to work with using the app.config file. the connection works when I use 'in line' connection as below:...
0
by: Simon Devlin | last post by:
Hi All, I've got some pages and I need to add a "offline" mode, where the pages are turned into a static html page for zipping and emailing back to the user (who then distributes this summary...
2
by: Vinod | last post by:
All, .NET Web Service needs to talk to third party software through TCP/IP sockets. Do we have any .Net Framework in place which can do a TCP/IP
5
by: Ya Ya | last post by:
I am trying to download a web page using WebRequest. The problem is that this page uses cookies. In IE, I can view this page correctly (since I have the cookie) but when downloading using...
7
by: mail747097 | last post by:
I would like to keep IIS alive on my web site and prevent Application_End from occuring in global.asax. Any ideas?
3
by: =?Utf-8?B?QXho?= | last post by:
Is there a limitation on the number of (sequential) opened connection for SQL Server User Instances? The following method will run to about the 240th iteration then will receive a timeout...
1
by: FFMG | last post by:
Hi, In safe mode, (http://www.php.net/manual/en/features.safe-mode.php#ini.safe-mode), set_time_limit(...) cannot be used. http://www.php.net/set_time_limit Is there a simple way around...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.