Avatar of Oracle4All
Oracle4All

asked on 

The name 'InitializeComponent' does not exist in the class or namespace 'HelloService.HelloService'

I'm trying to use the following ASP.NET web services tutorial, http://abstractvb.com/code.asp?A=1006. I'm using VS 2003 C#. I got to the point of running the service (F5) and I get the error listed in the title. I'm thinking that it may be a version issue but I'm too new to dot-net to recognize this for sure. My code duplicates the code listed on the site, so I won't paste it here.

Essentially, the InitializeComponent() method isn't recognized within the HelloService() method.

Any ideas? If you need more info, please let me know. I'm trying to pick up bits and pieces of dot-net knowledge here and there, so this isn't a mission-critical task.

Thanks all.
Michael Stelly
ASP.NET

Avatar of undefined
Last Comment
Oracle4All
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

Micheal,

Its just that in the example code on that page he's half left out some of the autogenerated code that is created when you create your own web service. The bit that is missing is:
            #region Component Designer generated code
                        
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
            }
            
            #endregion

InitializeComponent is used by the IDE to write the code when you use the property pane in the IDE to wire up event handlers and set properties of objects on the designer surface. You could just as easily remove the call to "InitializeComponent();" but it's probably better just to paste the code above back into your file.

Andy
Avatar of Oracle4All
Oracle4All

ASKER

It's still failing on the compile. What did I do wrong?  Here's my code after copying your solution.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace HelloService
{
      [WebService(
             Namespace="http://abstractvb.com/",
             Name="Hello Web Service in C#",
             Description="My Description")]
      public class HelloService : System.Web.Services.WebService
      {
            public HelloService()
            {
                  #region Component Designer generated code
                   
                  /// <summary>
                  /// Required method for Designer support - do not modify
                  /// the contents of this method with the code editor.
                  /// </summary>
                  private void InitializeComponent(){}
         
                  #endregion
            }

                  [WebMethod]
                  public string SayHello(String strMyName)
            {
                  return "Hello " + strMyName;
            }

                  [WebMethod]
                  public string SayGoodBye()
            {
                  return "Goodby!";
            }
      }      
}

And here are the errors:

c:\inetpub\wwwroot\WebService1\Service1.asmx.cs(18): } expected
c:\inetpub\wwwroot\WebService1\Service1.asmx.cs(18): } expected
c:\inetpub\wwwroot\WebService1\Service1.asmx.cs(31): Expected class, delegate, enum, interface, or struct
c:\inetpub\wwwroot\WebService1\Service1.asmx.cs(37): Expected class, delegate, enum, interface, or struct
c:\inetpub\wwwroot\WebService1\Service1.asmx.cs(42): Type or namespace definition, or end-of-file expected


Thanks for your quick response.
Michael Stelly
ASKER CERTIFIED SOLUTION
Avatar of AGBrown
AGBrown
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Oracle4All
Oracle4All

ASKER

I see what I did wrong, now. That whole 'method in a method' thing. Thanks for your help!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo