Solved

Understand web service better

Posted on 2011-09-07
5
224 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
ID: 36496115
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
ID: 36496748
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
ID: 36502957
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
ID: 36502995
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
ID: 36503073
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
optimization in c#? 4 58
wcf, asp.net, jquery /ajax restful 21 218
xml jquery 7 334
What exactly is WCF/ Silverlight and where it works in conjunction? 8 50
This tutorial will show you how to add an attribute to an XML (http://en.wikipedia.org/wiki/XML) stream returned from a Windows Communication Foundation (http://en.wikipedia.org/wiki/Windows_Communication_Foundation) (WCF) Web Service.  Some knowled…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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