[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Disable keepalive in webservice class

Posted on 2007-10-11
5
Medium Priority
?
3,763 Views
Last Modified: 2011-04-14
Hello, How can I turn off keep alive in the following class? I'm a newb with c# and with web services and would appreciate the help as I sometimes get the following error:

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

on this line of code:
 this.RawXml = ws.GetQuote(this.Symbol);

In this code block:
private void GetQuote()
    {
        using (StockQuoteService.StockQuote ws = new StockQuoteService.StockQuote())
        {
            this.RawXml = ws.GetQuote(this.Symbol);
        }

        XmlDocument doc = new XmlDocument();
        doc.InnerXml = this.RawXml;
        foreach (XmlNode node in doc.FirstChild.FirstChild.ChildNodes)
        {
            this.Parameters.Add(node.Name, node.InnerText);
        }
    }




using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Collections.Specialized;

/// <summary>
/// Summary description for StockQuote
/// </summary>
public class StockQuote
{
    private string _symbol = string.Empty;
    public string Symbol
    {
        get { return _symbol; }
        set { _symbol = value; }
    }

    private string _raw_xml = string.Empty;
    public string RawXml
    {
        get { return _raw_xml; }
        set { _raw_xml = value; }
    }

    private NameValueCollection _parameters = new NameValueCollection();
    public NameValueCollection Parameters
    {
        get { return _parameters; }
        set { _parameters = value; }
    }

    public string Last
    {
        get { return GetParameter("Last"); }
    }

    public DateTime QuoteDateTime
    {
        get
        {
            DateTime dVal = DateTime.Now;
            DateTime.TryParse(GetParameter("Date") + " " + GetParameter("Time"), out dVal);
            return dVal;
        }
    }

    public string Change
    {
        get { return GetParameter("Change"); }
    }


      public StockQuote()
      {
            //
            // TODO: Add constructor logic here
            //
      }

    public StockQuote(string symbol)
    {
        this.Symbol = symbol;
        GetQuote();
    }

    private void GetQuote()
    {
        using (StockQuoteService.StockQuote ws = new StockQuoteService.StockQuote())
        {
            this.RawXml = ws.GetQuote(this.Symbol);
        }

        XmlDocument doc = new XmlDocument();
        doc.InnerXml = this.RawXml;
        foreach (XmlNode node in doc.FirstChild.FirstChild.ChildNodes)
        {
            this.Parameters.Add(node.Name, node.InnerText);
        }
    }

    private string GetParameter(string key)
    {
        if (this.Parameters[key] == null)
        {
            throw new Exception(string.Format("I could not find the key ({0}) you are looking for", key));
        }
        return this.Parameters[key];
    }

}





0
Comment
Question by:gogetsome
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20063071
Hi, add this to your webservice

protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
0
 

Author Comment

by:gogetsome
ID: 20064963
Hey RedKevin thanks for your reply! I have seen that bit of code, but don't know where to put it. New to web services. I'm consuming the service from http://www.webservicex.net/WCF/default.aspx.

This is the actual service: http://www.webservicex.net/WCF/default.aspx
0
 
LVL 22

Accepted Solution

by:
RedKelvin earned 2000 total points
ID: 20065199
Take a look at this, it will tell you step by step
http://weblogs.asp.net/jan/archive/2004/01/28/63771.aspx
0
 

Author Comment

by:gogetsome
ID: 20065494
I'm trying to find the Reference.vb file but it does not seem to be in my project. Actually, Reference.vb is not on my whole computer. How can that be?
0
 

Author Comment

by:gogetsome
ID: 20066805
I have learned that Reference.vb is not part of an ASP.net project.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question