Managing webservice connections and/or sessions on clint side

Discussion in 'ASP .Net Web Services' started by Kursat, Oct 13, 2009.

  1. Kursat

    Kursat Guest

    Hi,

    I am employing a webservice in my C# application. I have generated proxy
    class for the web service thus I instantiate an object from that class like
    it is local, use it and let it garbage collected.
    That is all for my side but I don't have any idea about what happens on the
    server side. There will be an HTTP connection between client and server. Is
    this connection automatically closed by the infrastructure when the
    webservice proxy object is finalized? What about the Session on the server
    side, when is it closed? Is there anything I should do explicitly with the
    webservice proxy object to close http connection and session on server side?

    Thanks in advance.
    Kursat, Oct 13, 2009
    #1
    1. Advertising

  2. Kursat

    Kursat Guest

    But the Web Service proxy class inherits non-virtual Dispose method from
    "Component" class which doesn't know anything about connection closure.
    Right?

    "Mr. Arnold" <MR. > wrote in message
    news:...
    >
    > "Kursat" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> I am employing a webservice in my C# application. I have generated proxy
    >> class for the web service thus I instantiate an object from that class
    >> like it is local, use it and let it garbage collected.
    >> That is all for my side but I don't have any idea about what happens on
    >> the server side. There will be an HTTP connection between client and
    >> server. Is this connection automatically closed by the infrastructure
    >> when the webservice proxy object is finalized? What about the Session on
    >> the server side, when is it closed? Is there anything I should do
    >> explicitly with the webservice proxy object to close http connection and
    >> session on server side?
    >>

    >
    > You open the Web service connection from the client, and then it's the
    > client's responsibility to close the connection with a Dispose().
    >
    > Web services are session less by default unless you have written code in
    > the Web service to keep session data.
    >
    >
    >
    > __________ Information from ESET NOD32 Antivirus, version of virus
    > signature database 4504 (20091013) __________
    >
    > The message was checked by ESET NOD32 Antivirus.
    >
    > http://www.eset.com
    >
    >
    >
    Kursat, Oct 14, 2009
    #2
    1. Advertising

  3. Kursat

    Mr. Arnold Guest

    "Kursat" <> wrote in message
    news:...
    > But the Web Service proxy class inherits non-virtual Dispose method from
    > "Component" class which doesn't know anything about connection closure.
    > Right?


    I don't use proxy. However, the proxy class is on the client side, and it's
    doing the Dispose() of the connection. It's the same thing. If you were not
    using a proxy, then you are still responsible for the close of the
    connection with a Dispose() at some point in your code that would not be
    using a proxy.

    If you don't Dispose() the Web service is some fashion in code, then the
    Web server itself is going to close the connection on a timeout to release
    resources, so the Web server can process other requests of other Web server
    clients, and you don't want that.




    __________ Information from ESET NOD32 Antivirus, version of virus signature database 4504 (20091013) __________

    The message was checked by ESET NOD32 Antivirus.

    http://www.eset.com
    Mr. Arnold, Oct 14, 2009
    #3
  4. Kursat

    Kursat Guest

    Hi Arnold,

    Thanks for your help but I cant understand. I have a schema file for the web
    service and I generated a proxy class by using wsdl.exe. My proxy class
    doesn't have any method for connection closing. It just inherits a Dispose
    method from "Component" class and I can't use the connection by using this
    method. What should I do in this case? You said I am not using proxy class,
    what do you for using web services?

    Thanks


    "Mr. Arnold" <MR. > wrote in message
    news:...
    >
    > "Kursat" <> wrote in message
    > news:...
    >> But the Web Service proxy class inherits non-virtual Dispose method from
    >> "Component" class which doesn't know anything about connection closure.
    >> Right?

    >
    > I don't use proxy. However, the proxy class is on the client side, and
    > it's doing the Dispose() of the connection. It's the same thing. If you
    > were not using a proxy, then you are still responsible for the close of
    > the connection with a Dispose() at some point in your code that would not
    > be using a proxy.
    >
    > If you don't Dispose() the Web service is some fashion in code, then the
    > Web server itself is going to close the connection on a timeout to release
    > resources, so the Web server can process other requests of other Web
    > server clients, and you don't want that.
    >
    >
    >
    >
    > __________ Information from ESET NOD32 Antivirus, version of virus
    > signature database 4504 (20091013) __________
    >
    > The message was checked by ESET NOD32 Antivirus.
    >
    > http://www.eset.com
    >
    >
    >
    Kursat, Oct 14, 2009
    #4
  5. Kursat

    Mr. Arnold Guest

    "Kursat" <> wrote in message
    news:%...
    > Hi Arnold,
    >
    > Thanks for your help but I cant understand. I have a schema file for the
    > web service and I generated a proxy class by using wsdl.exe. My proxy
    > class doesn't have any method for connection closing. It just inherits a
    > Dispose method from "Component" class and I can't use the connection by
    > using this method. What should I do in this case? You said I am not using
    > proxy class, what do you for using web services?
    >


    I don't use a proxy class created by wsdl.exe. I don't know what control
    you have over the Web service or your client project, but you can set a Web
    Service reference to the Web service over HTTP to a remote Web service
    localhost or remote Web service over the Internet.

    ..NET will take care of everything so you don't have to use wsdl.exe '
    generated class, if you use a Web reference in the client project.

    http://msdn.microsoft.com/en-us/library/xb5th1ba(VS.80).aspx

    I would still do a ws.Dispose() to kill the connection that's being shown to
    you in the examples.


    It's also being talked about 'Web Service Reference' in a client project on
    page 240.

    <http://books.google.com/books?id=YC1H0QkLPvsC&pg=PA234&lpg=PA234&dq=calling+a+web+method+from+c%23.net&source=bl&ots=O5XEjpoAlB&sig=_mxgvycVYEuluqCT_PelioVA3z4&hl=en&ei=QUXVSsbGHoaGtgeqz6CdAw&sa=X&oi=book_result&ct=result&resnum=6&ved=0CBsQ6AEwBQ#v=onepage&q=calling%20a%20web%20method%20from%20c%23.net&f=false>


    __________ Information from ESET NOD32 Antivirus, version of virus signature database 4504 (20091013) __________

    The message was checked by ESET NOD32 Antivirus.

    http://www.eset.com
    Mr. Arnold, Oct 14, 2009
    #5
  6. Kursat

    Kursat Guest

    I know using Web References and the book says generating proxy classes and
    adding web references have same results. What I have will be a proxy class
    over which I can call webmethods. But the problem is that the class doesn't
    implement Dispose() method it just inherit it from the "Component" class
    which is useless for connection closing. Does your class implement Dispose()
    when you ass web reference? If yes can you send the implementation?

    Thanks.

    "Mr. Arnold" <MR. > wrote in message
    news:...
    >
    > "Kursat" <> wrote in message
    > news:%...
    >> Hi Arnold,
    >>
    >> Thanks for your help but I cant understand. I have a schema file for the
    >> web service and I generated a proxy class by using wsdl.exe. My proxy
    >> class doesn't have any method for connection closing. It just inherits a
    >> Dispose method from "Component" class and I can't use the connection by
    >> using this method. What should I do in this case? You said I am not using
    >> proxy class, what do you for using web services?
    >>

    >
    > I don't use a proxy class created by wsdl.exe. I don't know what control
    > you have over the Web service or your client project, but you can set a
    > Web Service reference to the Web service over HTTP to a remote Web service
    > localhost or remote Web service over the Internet.
    >
    > .NET will take care of everything so you don't have to use wsdl.exe '
    > generated class, if you use a Web reference in the client project.
    >
    > http://msdn.microsoft.com/en-us/library/xb5th1ba(VS.80).aspx
    >
    > I would still do a ws.Dispose() to kill the connection that's being shown
    > to you in the examples.
    >
    >
    > It's also being talked about 'Web Service Reference' in a client project
    > on page 240.
    >
    > <http://books.google.com/books?id=YC1H0QkLPvsC&pg=PA234&lpg=PA234&dq=calling+a+web+method+from+c%23.net&source=bl&ots=O5XEjpoAlB&sig=_mxgvycVYEuluqCT_PelioVA3z4&hl=en&ei=QUXVSsbGHoaGtgeqz6CdAw&sa=X&oi=book_result&ct=result&resnum=6&ved=0CBsQ6AEwBQ#v=onepage&q=calling%20a%20web%20method%20from%20c%23.net&f=false>
    >
    >
    > __________ Information from ESET NOD32 Antivirus, version of virus
    > signature database 4504 (20091013) __________
    >
    > The message was checked by ESET NOD32 Antivirus.
    >
    > http://www.eset.com
    >
    >
    >
    Kursat, Oct 14, 2009
    #6
  7. Kursat

    Kursat Guest

    I added a web reference and it generated the same class. It just inherit
    Dispose() from "Component" class.

    "Kursat" <> wrote in message
    news:ep$...
    >I know using Web References and the book says generating proxy classes and
    >adding web references have same results. What I have will be a proxy class
    >over which I can call webmethods. But the problem is that the class doesn't
    >implement Dispose() method it just inherit it from the "Component" class
    >which is useless for connection closing. Does your class implement
    >Dispose() when you ass web reference? If yes can you send the
    >implementation?
    >
    > Thanks.
    >
    > "Mr. Arnold" <MR. > wrote in message
    > news:...
    >>
    >> "Kursat" <> wrote in message
    >> news:%...
    >>> Hi Arnold,
    >>>
    >>> Thanks for your help but I cant understand. I have a schema file for the
    >>> web service and I generated a proxy class by using wsdl.exe. My proxy
    >>> class doesn't have any method for connection closing. It just inherits a
    >>> Dispose method from "Component" class and I can't use the connection by
    >>> using this method. What should I do in this case? You said I am not
    >>> using proxy class, what do you for using web services?
    >>>

    >>
    >> I don't use a proxy class created by wsdl.exe. I don't know what control
    >> you have over the Web service or your client project, but you can set a
    >> Web Service reference to the Web service over HTTP to a remote Web
    >> service localhost or remote Web service over the Internet.
    >>
    >> .NET will take care of everything so you don't have to use wsdl.exe '
    >> generated class, if you use a Web reference in the client project.
    >>
    >> http://msdn.microsoft.com/en-us/library/xb5th1ba(VS.80).aspx
    >>
    >> I would still do a ws.Dispose() to kill the connection that's being shown
    >> to you in the examples.
    >>
    >>
    >> It's also being talked about 'Web Service Reference' in a client project
    >> on page 240.
    >>
    >> <http://books.google.com/books?id=YC1H0QkLPvsC&pg=PA234&lpg=PA234&dq=calling+a+web+method+from+c%23.net&source=bl&ots=O5XEjpoAlB&sig=_mxgvycVYEuluqCT_PelioVA3z4&hl=en&ei=QUXVSsbGHoaGtgeqz6CdAw&sa=X&oi=book_result&ct=result&resnum=6&ved=0CBsQ6AEwBQ#v=onepage&q=calling%20a%20web%20method%20from%20c%23.net&f=false>
    >>
    >>
    >> __________ Information from ESET NOD32 Antivirus, version of virus
    >> signature database 4504 (20091013) __________
    >>
    >> The message was checked by ESET NOD32 Antivirus.
    >>
    >> http://www.eset.com
    >>
    >>
    >>

    >
    >
    Kursat, Oct 14, 2009
    #7
  8. Kursat

    milop Guest

    Just use "using":

    using (MyWebService ws = new MyWebService())
    {
    ws.DoSomething();
    }

    At this point the webservice instance has been disposed of.


    "Kursat" <> wrote in message
    news:...
    >I added a web reference and it generated the same class. It just inherit
    >Dispose() from "Component" class.
    >
    > "Kursat" <> wrote in message
    > news:ep$...
    >>I know using Web References and the book says generating proxy classes and
    >>adding web references have same results. What I have will be a proxy class
    >>over which I can call webmethods. But the problem is that the class
    >>doesn't implement Dispose() method it just inherit it from the "Component"
    >>class which is useless for connection closing. Does your class implement
    >>Dispose() when you ass web reference? If yes can you send the
    >>implementation?
    >>
    >> Thanks.
    >>
    >> "Mr. Arnold" <MR. > wrote in message
    >> news:...
    >>>
    >>> "Kursat" <> wrote in message
    >>> news:%...
    >>>> Hi Arnold,
    >>>>
    >>>> Thanks for your help but I cant understand. I have a schema file for
    >>>> the web service and I generated a proxy class by using wsdl.exe. My
    >>>> proxy class doesn't have any method for connection closing. It just
    >>>> inherits a Dispose method from "Component" class and I can't use the
    >>>> connection by using this method. What should I do in this case? You
    >>>> said I am not using proxy class, what do you for using web services?
    >>>>
    >>>
    >>> I don't use a proxy class created by wsdl.exe. I don't know what
    >>> control you have over the Web service or your client project, but you
    >>> can set a Web Service reference to the Web service over HTTP to a remote
    >>> Web service localhost or remote Web service over the Internet.
    >>>
    >>> .NET will take care of everything so you don't have to use wsdl.exe '
    >>> generated class, if you use a Web reference in the client project.
    >>>
    >>> http://msdn.microsoft.com/en-us/library/xb5th1ba(VS.80).aspx
    >>>
    >>> I would still do a ws.Dispose() to kill the connection that's being
    >>> shown to you in the examples.
    >>>
    >>>
    >>> It's also being talked about 'Web Service Reference' in a client project
    >>> on page 240.
    >>>
    >>> <http://books.google.com/books?id=YC1H0QkLPvsC&pg=PA234&lpg=PA234&dq=calling+a+web+method+from+c%23.net&source=bl&ots=O5XEjpoAlB&sig=_mxgvycVYEuluqCT_PelioVA3z4&hl=en&ei=QUXVSsbGHoaGtgeqz6CdAw&sa=X&oi=book_result&ct=result&resnum=6&ved=0CBsQ6AEwBQ#v=onepage&q=calling%20a%20web%20method%20from%20c%23.net&f=false>
    >>>
    >>>
    >>> __________ Information from ESET NOD32 Antivirus, version of virus
    >>> signature database 4504 (20091013) __________
    >>>
    >>> The message was checked by ESET NOD32 Antivirus.
    >>>
    >>> http://www.eset.com
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
    milop, Oct 16, 2009
    #8
  9. Kursat

    Mr. Arnold Guest

    "milop" <> wrote in message
    news:eKY$...
    > Just use "using":
    >
    > using (MyWebService ws = new MyWebService())
    > {
    > ws.DoSomething();
    > }
    >
    > At this point the webservice instance has been disposed of.
    >


    The above is not a good practice, and as a matter of fact, when using a WCF
    Web service, there is documentation that specifically indicates not to use
    the Using statement on client connection to the WCF Web service.

    http://www.devx.com/dotnet/Article/39023

    WCF Webservice

    var ws = new Webservice();

    ws.DoSomething;

    ws.Close();

    legacy Webservice

    var ws = new Webservice();

    ws.DoSomething;

    ws.Dispose();


    __________ Information from ESET NOD32 Antivirus, version of virus signature database 4516 (20091016) __________

    The message was checked by ESET NOD32 Antivirus.

    http://www.eset.com
    Mr. Arnold, Oct 17, 2009
    #9
  10. Kursat

    milop Guest

    Well, the bottom line is proper class design, knowledge of managed and
    unmanged resources and garbage collection, and disciplined programming
    practices.

    Although, spcifically calling Dispose() on an object doesn't hurt. Hell, I
    even erase arrays when they're no longer going to be used. I don't want to
    wait for the GC (I have a C++ background :) )


    "Mr. Arnold" <MR. > wrote in message
    news:...
    >
    > "milop" <> wrote in message
    > news:eKY$...
    >> Just use "using":
    >>
    >> using (MyWebService ws = new MyWebService())
    >> {
    >> ws.DoSomething();
    >> }
    >>
    >> At this point the webservice instance has been disposed of.
    >>

    >
    > The above is not a good practice, and as a matter of fact, when using a
    > WCF Web service, there is documentation that specifically indicates not to
    > use the Using statement on client connection to the WCF Web service.
    >
    > http://www.devx.com/dotnet/Article/39023
    >
    > WCF Webservice
    >
    > var ws = new Webservice();
    >
    > ws.DoSomething;
    >
    > ws.Close();
    >
    > legacy Webservice
    >
    > var ws = new Webservice();
    >
    > ws.DoSomething;
    >
    > ws.Dispose();
    >
    >
    > __________ Information from ESET NOD32 Antivirus, version of virus
    > signature database 4516 (20091016) __________
    >
    > The message was checked by ESET NOD32 Antivirus.
    >
    > http://www.eset.com
    >
    >
    >
    milop, Oct 17, 2009
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. WilsonSmith

    Clint side and server side event

    WilsonSmith, Jul 16, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    528
    WilsonSmith
    Jul 17, 2004
  2. Nick Gilbert
    Replies:
    14
    Views:
    2,754
    William \(Bill\) Vaughn
    Jul 6, 2005
  3. Replies:
    4
    Views:
    2,500
  4. Richard Heathfield

    ANN: CLINT sixmonthiversary release

    Richard Heathfield, Dec 31, 2003, in forum: C Programming
    Replies:
    1
    Views:
    385
    Richard Heathfield
    Jan 3, 2004
  5. =?Utf-8?B?QUo=?=

    Managing Database Connections!

    =?Utf-8?B?QUo=?=, Sep 5, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    458
    Mark Rae
    Sep 6, 2006
Loading...

Share This Page