Solved

Understand web service better

Posted on 2011-09-07
5
221 Views
Last Modified: 2012-05-12
Hi although I used web service a lot of times, but to be honest,I still can't clearly figure out the real meaning of "web service"

For ex,
 [WebMethod]
    public string HelloWorld(string yourName) {
        return string.Format("Hello {0}",yourName);
    }

Open in new window

If without [WebMethod]
The program still can return the string, so what is the difference?
0
Comment
Question by:zhshqzyc
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:eridanix
Comment Utility
Hi,

good explanation of [WebMethod] attribute is under the link http://oreilly.com/catalog/prognetws/chapter/ch02.html

Search the "The WebMethod attribute", It's on more parts of page.
0
 

Author Comment

by:zhshqzyc
Comment Utility
My question is not how to use [WebMethod].
It is WebService vs Regualr Service.

So
[WebMethod]
    public string HelloWorld(string yourName) {
        return string.Format("Hello {0}",yourName);
    } 

Open in new window

run at server?
    public string HelloWorld(string yourName) {
        return string.Format("Hello {0}",yourName);
    } 

Open in new window

run at local?
0
 
LVL 5

Expert Comment

by:eridanix
Comment Utility
Yes

The [WebMethod] attribute means, that you want the method exposed as part of the XML Web service.

Without this parameter, you can use method only inside of web service, but cannot call it from other application, which is using your WebService.
0
 

Author Comment

by:zhshqzyc
Comment Utility
A follow up silly question, since we can embed the method into an application, why we need call it from the server?

Please use an example to explain it? For example, Hello World can be run on the local machine.
0
 
LVL 5

Accepted Solution

by:
eridanix earned 500 total points
Comment Utility
So, why do you create Web Service (in this meaning http://msdn.microsoft.com/en-us/library/ms972326.aspx)
and not create only classic method right in your application?

Web services are usefull only if you want to access to it from other application or applications (and maybe from other server).


[WebMethod]
    public string HelloWorld(string yourName) {
        return string.Format("Hello {0}",yourName);
    }
- this method is part of ASP.NET Web Service and can be call remotely

public string HelloWorld(string yourName) {
        return string.Format("Hello {0}",yourName);
    }
- this is classic method and can be call only within its application (in class or by instances of this class, or in inherited classes by interfaces)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In previous Articles, we have discussed how we can upload a file using .asmx web service and isolated storage space. Here, in continuation to the topic, I am going to discuss how we can use WCF for the same purpose. Steps: 1.Create the silverli…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

9 Experts available now in Live!

Get 1:1 Help Now