Solved

Understand web service better

Posted on 2011-09-07
5
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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