Sorry,
Web services code is: Service1.asmx.cs
client application code is:WebForm1.aspx.cs
Valentina.
>Scrive Jonathan Stowe <[EMAIL PROTECTED]>:
> On Fri, 2004-07-16 at 09:14, [EMAIL PROTECTED] wrote:
> <snip>
> > The Web services code is: Contatore.asmx.cs
> > The client application code is: CounterCLI.aspx.cs
> >
> > Could anybody help me please?
>
> Your attachments appear to be formatted formatted as RTF please could
> you send them again.
>
> /J\
>
>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
namespace CounterCLI
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
// Create a new instance of a proxy class for your XML Web service.
private ServerUsage.Service1 su = new ServerUsage.Service1();
private CookieContainer cookieJar;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new
System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
// Check to see if the cookies have already been saved for
this session.
if (Session["CookieJar"] == null)
cookieJar= new CookieContainer();
else
cookieJar = (CookieContainer) Session["CookieJar"];
// Assign the CookieContainer to the proxy class.
su.CookieContainer = cookieJar;
// Invoke an XML Web service method that uses session state
and thus cookies.
int count = su.SessionHitCounter();
// Store the cookies received in the session state for future
retrieval by this session.
Session["CookieJar"] = cookieJar;
// Populate the text box with the results from the call to the
XML Web service method.
Label1.Text = count.ToString();
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace Contatore
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services
Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the
project
// To test this web service, press F5
[ WebMethod(Description="Per session Hit Counter",EnableSession=true)]
public int SessionHitCounter()
{
if (Session["HitCounter"] == null)
{
Session["HitCounter"] = 1;
}
else
{
Session["HitCounter"] = ((int) Session["HitCounter"])
+ 1;
}
return ((int) Session["HitCounter"]);
}
}
}