Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Web Services +WebServiceUtil Proxy's Help!!!


Message #1 by "Albert Davis" <albertdavis@h...> on Wed, 18 Apr 2001 13:01:40 -0400
Has anyone have success developing a webservice in c# and invoking it via a

winform (either C#,VB7 - doesn't matter) using a Proxy created with the

WebServiceUtil to successfully return values?



I have created a web service in c# with VS.NET and just uncommented the

"HelloWorld()" [web method], then compiled and invoked it via a browser.

Everything has worked so far.  Then I wanted to invoke the web method via a

winform in c# or VB7 (doesn't really matter) so I used MS's WebServiceUtil

and created a proxy.  I then started up a new project and copied the code

generated by the WebServiceUtil and pasted it in the new C# library project

within a namespace (the tool didn't do this for me by default) and added the

appropriate references to the librarys the proxy used.  I then compiled the

library.  Then I started up a winform project and added reference to my

newly created C# Library Proxy Component.  My winform just has a button.

When the button is clicked the only thing that happens (for testing

purposes) is I called the web method within a

MessageBox.Show(oWs.HelloWorld()); and nothing happens...  On the web server

I see a request being made and on my machine I see the request being made

from my winform app as well, but nothing gets returned, it just locks up the

application...  Then if I look at the task manager, it says that the winform

app is not responding...  I've also tryed skipping the proxy bit all

together and try using a web reference instead, but I get the same result as

when using the Proxy... What gives?



Is there anything special that I should be doing?  Has anyone had any luck

getting this to work?



----------------------------

Here is my web service code:

----------------------------

namespace WebService1

{

    using System;

    using System.Collections;

    using System.Configuration;

    using System.ComponentModel;

    using System.Data;

    using System.Diagnostics;

    using System.Web;

    using System.Web.Services;



    /// <summary>

    ///    Summary description for WebService1.

    /// </summary>

    public class WebService1 : System.Web.Services.WebService

    {

        public WebService1()

        {

            //CODEGEN: This call is required by the ASP+ Web Services

Designer

            InitializeComponent();

        }



        /// <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>

        public override void Dispose()

        {

        }



        //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, right-click the Web Service's .asmx file and select View

in Browser

        //

        [WebMethod]

        public string HelloWorld()

        {

            return "Hello World";

        }

    }

}



-------------------------

Here is my C# proxy code:

-------------------------

namespace ClassLibrary1

{

        using System;

	using System.Xml.Serialization;

	using System.Web.Services.Protocols;

	using System.Web.Services;





    public class WebService1 :

System.Web.Services.Protocols.SoapClientProtocol{



	public WebService1() {

	    this.Url = "http://127.0.0.1/WebService1/WebService1.asmx";

	}



	[System.Web.Services.Protocols.SoapMethodAttribute

"http://tempuri.org/HelloWorld")]

	public string HelloWorld() {

	    object[] results = this.Invoke("HelloWorld", new object[0]);

	    return (string)(results[0]);

	}

	public System.IAsyncResult BeginHelloWorld(System.AsyncCallback callback,

object asyncState){

	    return this.BeginInvoke("HelloWorld", new object[0], callback,

asyncState);

	}



        public string EndHelloWorld(System.IAsyncResult asyncResult){

            object[] results = this.EndInvoke(asyncResult);

	    return (string)(results[0]);

        }

    }

}



--------------------------------

Here is my winform project code:

--------------------------------



namespace WindowsApplication1

{

    using System;

    using System.Drawing;

    using System.Collections;

    using System.ComponentModel;

    using System.WinForms;

    using System.Data;

    using ClassLibrary1;



    /// <summary>

    ///    Summary description for Form1.

    /// </summary>

    public class Form1 : System.WinForms.Form

    {

        /// <summary>

        ///    Required designer variable.

        /// </summary>

        private System.ComponentModel.Container components;

		private System.WinForms.Button button1;



        public Form1()

        {

            //

            // Required for Windows Form Designer support

            //

            InitializeComponent();



            //

            // TODO: Add any constructor code after InitializeComponent call

            //

        }



        /// <summary>

        ///    Clean up any resources being used.

        /// </summary>

        public override void Dispose()

        {

            base.Dispose();

            components.Dispose();

        }



        /// <summary>

        ///    Required method for Designer support - do not modify

        ///    the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

		{

			this.components = new System.ComponentModel.Container ();

			this.button1 = new System.WinForms.Button ();

			//@this.TrayHeight = 0;

			//@this.TrayLargeIcon = false;

			//@this.TrayAutoArrange = true;

			button1.Location = new System.Drawing.Point (40, 16);

			button1.Size = new System.Drawing.Size (75, 23);

			button1.TabIndex = 0;

			button1.Text = "button1";

			button1.Click += new System.EventHandler (this.button1_Click);

			this.Text = "Form1";

			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);

			this.ClientSize = new System.Drawing.Size (144, 61);

			this.Controls.Add (this.button1);

		}



		protected void button1_Click (object sender, System.EventArgs e){

			WebService1 oWs = new WebService1();

			MessageBox.Show(oWs.HelloWorld());

		}



        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        public static void Main(string[] args)

        {

            Application.Run(new Form1());

        }

    }

}





Thanks in advance for any help,

-- Al



Message #2 by "Rob Howard" <rhoward@m...> on Thu, 19 Apr 2001 07:39:27 -0700
Hi Al,



I copied your code and instructions exactly -- with the exception that

the URI for my service is:

http://127.0.0.1/test/WebService/WebService1.asmx.



Mine worked as expected :(



Do you happen to have a non-default hosts file that maps 127.0.0.1 to a

different host name? Try using your host name, either localhost or the

name of your server instead of 127.0.0.1.



If that still doesn't work, give me a shout.



Thanks,

Rob



-----Original Message-----

From: Albert Davis [mailto:albertdavis@h...]

Sent: Wednesday, April 18, 2001 10:02 AM

To: ASP+

Subject: [aspx] Web Services +WebServiceUtil Proxy's Help!!!



Has anyone have success developing a webservice in c# and invoking it

via a

winform (either C#,VB7 - doesn't matter) using a Proxy created with the

WebServiceUtil to successfully return values?



I have created a web service in c# with VS.NET and just uncommented the

"HelloWorld()" [web method], then compiled and invoked it via a browser.

Everything has worked so far.  Then I wanted to invoke the web method

via a

winform in c# or VB7 (doesn't really matter) so I used MS's

WebServiceUtil

and created a proxy.  I then started up a new project and copied the

code

generated by the WebServiceUtil and pasted it in the new C# library

project

within a namespace (the tool didn't do this for me by default) and added

the

appropriate references to the librarys the proxy used.  I then compiled

the

library.  Then I started up a winform project and added reference to my

newly created C# Library Proxy Component.  My winform just has a button.

When the button is clicked the only thing that happens (for testing

purposes) is I called the web method within a

MessageBox.Show(oWs.HelloWorld()); and nothing happens...  On the web

server

I see a request being made and on my machine I see the request being

made

from my winform app as well, but nothing gets returned, it just locks up

the

application...  Then if I look at the task manager, it says that the

winform

app is not responding...  I've also tryed skipping the proxy bit all

together and try using a web reference instead, but I get the same

result as

when using the Proxy... What gives?



Is there anything special that I should be doing?  Has anyone had any

luck

getting this to work?



----------------------------

Here is my web service code:

----------------------------

namespace WebService1

{

    using System;

    using System.Collections;

    using System.Configuration;

    using System.ComponentModel;

    using System.Data;

    using System.Diagnostics;

    using System.Web;

    using System.Web.Services;



    /// <summary>

    ///    Summary description for WebService1.

    /// </summary>

    public class WebService1 : System.Web.Services.WebService

    {

        public WebService1()

        {

            //CODEGEN: This call is required by the ASP+ Web Services

Designer

            InitializeComponent();

        }



        /// <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>

        public override void Dispose()

        {

        }



        //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, right-click the Web Service's .asmx file and select

View

in Browser

        //

        [WebMethod]

        public string HelloWorld()

        {

            return "Hello World";

        }

    }

}



-------------------------

Here is my C# proxy code:

-------------------------

namespace ClassLibrary1

{

        using System;

	using System.Xml.Serialization;

	using System.Web.Services.Protocols;

	using System.Web.Services;





    public class WebService1 :

System.Web.Services.Protocols.SoapClientProtocol{



	public WebService1() {

	    this.Url =3D "http://127.0.0.1/WebService1/WebService1.asmx";

	}



	[System.Web.Services.Protocols.SoapMethodAttribute

"http://tempuri.org/HelloWorld")]

	public string HelloWorld() {

	    object[] results =3D this.Invoke("HelloWorld", new object[0]);

	    return (string)(results[0]);

	}

	public System.IAsyncResult BeginHelloWorld(System.AsyncCallback

callback,

object asyncState){

	    return this.BeginInvoke("HelloWorld", new object[0],

callback,

asyncState);

	}



        public string EndHelloWorld(System.IAsyncResult asyncResult){

            object[] results =3D this.EndInvoke(asyncResult);

	    return (string)(results[0]);

        }

    }

}



--------------------------------

Here is my winform project code:

--------------------------------



namespace WindowsApplication1

{

    using System;=09

    using System.Drawing;

    using System.Collections;

    using System.ComponentModel;

    using System.WinForms;

    using System.Data;

    using ClassLibrary1;



    /// <summary>

    ///    Summary description for Form1.

    /// </summary>

    public class Form1 : System.WinForms.Form

    {

        /// <summary>

        ///    Required designer variable.

        /// </summary>

        private System.ComponentModel.Container components;

		private System.WinForms.Button button1;



        public Form1()

        {

            //

            // Required for Windows Form Designer support

            //

            InitializeComponent();



            //

            // TODO: Add any constructor code after InitializeComponent

call

            //

        }



        /// <summary>

        ///    Clean up any resources being used.

        /// </summary>

        public override void Dispose()

        {

            base.Dispose();

            components.Dispose();

        }



        /// <summary>

        ///    Required method for Designer support - do not modify

        ///    the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

		{

			this.components =3D new

System.ComponentModel.Container ();

			this.button1 =3D new System.WinForms.Button ();

			//@this.TrayHeight =3D 0;

			//@this.TrayLargeIcon =3D false;

			//@this.TrayAutoArrange =3D true;

			button1.Location =3D new System.Drawing.Point (40,

16);

			button1.Size =3D new System.Drawing.Size (75, 23);

			button1.TabIndex =3D 0;

			button1.Text =3D "button1";

			button1.Click +=3D new System.EventHandler

(this.button1_Click);

			this.Text =3D "Form1";

			this.AutoScaleBaseSize =3D new System.Drawing.Size

(5, 13);

			this.ClientSize =3D new System.Drawing.Size (144,

61);

			this.Controls.Add (this.button1);

		}



		protected void button1_Click (object sender,

System.EventArgs e){

			WebService1 oWs =3D new WebService1();

			MessageBox.Show(oWs.HelloWorld());

		}



        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        public static void Main(string[] args)

        {

            Application.Run(new Form1());

        }

    }

}





Thanks in advance for any help,

-- Al


  Return to Index