Solved

Understand web service better

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Consume WCF web service from VBA 1 274
wcf vs wev services 2 190
Web Service echo on endpoint? 1 96
Adding  DYMO Labelprinter to c# client application 4 177
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…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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