Solved

Understand web service better

Posted on 2011-09-07
5
226 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

735 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