• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Where do I locate the web methods?

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?

thanks,
newbiweb
0
newbieweb
Asked:
newbieweb
3 Solutions
 
Solar_FlareCommented:
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.

0
 
newbiewebAuthor Commented:
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?
0
 
tppradeep18Commented:
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:
    [WebMethod]
    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
0
 
chinu1310Commented:
Check my post here.

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22721096.html

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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now