Hey guys. I'm running into an issue here and figured I'd ask for a bit of advice. I've got an app that needs to interface with a third party utility. Specifically, it needs to submit an address to the utility and have it process it for CASS certification.
The only "server mode" that this utility allows though, is it has a web interface that allows you to type in the criteria and submit them in. It can then respond back with either an HTML or XML file (your choice) which you can then parse.
So, my plan was simple: have my C# program simply hit the HTML page, get the XML response back, and then parse my data out of that.
The following function is one that I borrowed and modified a bit from a quick web example on doing this.
Using this, the program works just fine. Here is the code used to actually create the call the function and put the XML into a string. As you can tell, the original address that I'm sending is contained in a series of text boxes.
All comes back great. The problem however, is the speed. It's highly variable - taking anywhere from 5 to 15 seconds to get a response back from the web server. This really, really adds up when doing submissions. Thing is, submitting the web form from a browser results in a nearly instant response, leading me to believe that there is some issue there.
Any ideas on this? Any obvious reason why the function above would behave so slowly?
Thanks.
The only "server mode" that this utility allows though, is it has a web interface that allows you to type in the criteria and submit them in. It can then respond back with either an HTML or XML file (your choice) which you can then parse.
So, my plan was simple: have my C# program simply hit the HTML page, get the XML response back, and then parse my data out of that.
The following function is one that I borrowed and modified a bit from a quick web example on doing this.
Code:
private string GetResponseWithPost(string StrURL, string strPostData)
{
string strReturn = "";
HttpWebRequest objRequest = null;
ASCIIEncoding objEncoding = new ASCIIEncoding();
Stream reqStream = null;
HttpWebResponse objResponse = null;
StreamReader objReader = null;
try
{
objRequest = (HttpWebRequest)WebRequest.Create(StrURL);
objRequest.Method = "POST";
byte[] objBytes = objEncoding.GetBytes(strPostData);
objRequest.ContentLength = objBytes.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
reqStream = objRequest.GetRequestStream();
reqStream.Write(objBytes, 0, objBytes.Length);
objResponse = (HttpWebResponse)objRequest.GetResponse();
objReader = new StreamReader(objResponse.GetResponseStream());
strReturn = objReader.ReadToEnd();
}
catch (Exception exp)
{
throw exp;
}
finally
{
objRequest = null;
objEncoding = null;
reqStream = null;
if (objResponse != null)
objResponse.Close();
objResponse = null;
objReader = null;
}
return strReturn;
}
Using this, the program works just fine. Here is the code used to actually create the call the function and put the XML into a string. As you can tell, the original address that I'm sending is contained in a series of text boxes.
Code:
string response;
string postData = "company=" + textBoxOrigAddress1.Text + "&address=" + textBoxOrigAddress1.Text + "&address2=" + textBoxOrigAddress2.Text + "&city=" + textBoxOrigCity.Text + "&state=" + comboBoxOrigState.Text + "&zip=" + textBoxOrigZip.Text;
All comes back great. The problem however, is the speed. It's highly variable - taking anywhere from 5 to 15 seconds to get a response back from the web server. This really, really adds up when doing submissions. Thing is, submitting the web form from a browser results in a nearly instant response, leading me to believe that there is some issue there.
Any ideas on this? Any obvious reason why the function above would behave so slowly?
Thanks.