Where do I locate the web methods?

Posted on 2007-08-06
Last Modified: 2013-12-17
I'm new at creating web services from scratch, but have added code to existing ones.  I just made a new ASP.NET Wed Wervice Application but wonder where I place the web methods.  I have some idea how to create one, but do not want to stick in in the wrong place.

Can someone advise me on what file to use or how to structure where to add a new one to the project?

Question by:newbieweb
    LVL 15

    Assisted Solution

    if you add a new item and select Web Service (.asmx) then a new asmx file will be created. If you select "Separate Code File" then the web moethod code will be located in the App_Code folder, otherwise the web methods will sit directly in the asmx file.


    Author Comment

    How do I "add a new item"?  I am used to writing the entitre web method by hand.

    Or do you mean a new class?

    What kind of object structure should I create as it relates to web methods?  For example, if I need to write a GetVersion() function whih returns the version of the web service.  Should that be part of a class?  Or a web method simply stuck into the Web Service .asmx file?
    LVL 2

    Accepted Solution

    Yes you need to simply add your method to the class file of the asmx file.

    Below given are the details on how to begin from start:
    1.) In VS.NET 2005 click on File > New > Website > ASP.NET WebService
    2.) This will create a default webservice under the project e.g. Service.asmx with a code behind file Service.cs (exact name of class file will be mentioned in the first line of .asmx file)
    3.) Now in C# class u can see a default webmethod HelloWorld(). To add a new method to your service simply write the new method in this class and give [WebMethod] attribute for each method you want to be exposed in your service.
    4.) Example:
        public string MyMethod1() {
            return "I am visible in service ";

        public string MyMethod2() {
            return "I am not visible in service ";

    Hope that now your doubt is clear. Feel free to get back in case of any doubts.
    Thanks and Regards
    LVL 14

    Assisted Solution

    Check my post here.

    I have explained the way of creating web service and its method so that you can consume it. Let me know if you don't understand anything.

    Hope it helps.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now