CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> .NET / C# >> C# >> Web Services >> Tutorials


Web Services Using JavaScript and .NET
Learn to consume Web services from your client-side apps
Rating:

Prasad Kopanati (view profile)
June 5, 2006

Environment:  .NET, SOAP, Web Services

Go to page: 1  2  3  4  Next

Introduction

Test the Web service here: http://www.xemantex.com/consumeWebSvcDateTime.aspx


(continued)



I wrote this article because there are very few resources that elaborate on client-side consuming a Web service. This type of consuming is very handy when one has to make Web service calls to a remote Web server directly from the client. One can think of many instances where one would want to make Web service calls from the client. Look at this Web site, http://www.xemantex.com, for example, that uses the double-click on the client to call a Web service. Double-click on any word to get the word's meanings. On the other hand, calling Web services from the client has an added advantage of refreshing only that part of the Web page that accesses the Web service. A Web service call does not re-render the entire content on the page. Thus, one can attain a partial refresh of the Web page, providing a good improvement in the browsing efficiency for the end user.

A Web service is a function, method, or sub routine that is accessible not only to one computer (the owner or host) but also to any computer on the Internet. In a sense, a Web service is a collection of universally available functions.

Why Web Services?

The increasing usage of Web services is attributed to the fact that they enable easy sharing of an application across the Internet. You can find a single Web site serving for diverse functions such as stock quotes, weather information, and airline tickets. It is quite possible that the Web site directly provides for all these services, but in most cases each of the services would be powered by a third party that specializes in it. For example, http://www.weather.com is a good source for weather information.

Similarly, http://www.google.com is excellent resource for searching the Web. Instead of creating tools that cater to weather and/or Web search tools, a Web site owner or a solution provider may obtain services from Weather.com or Google.com for those respective needs. This approach not only saves time but also enables the site to provide reliable, accurate, and consistent information to the end user. Services like these that are made available to other computers anywhere in the world via the Internet are called Web services.

.NET has supplemented the easy creation and usage of Web services. Web services in .NET utilize open standards such as HTTP, SOAP, XML, and WSDL that allow for fast creation, extension, and deployment. Creating a Web service using .NET is a snap. You will look into creating and consuming a Web service in the following paragraphs.

Code Sample

For the sake of simplicity, you can create a Web service that returns a Web server's current date and time. Because this is a Web service, this will return the date and time of the geographical location where its server is located. If the Web server is in Chicago, USA, you will get the local time at Chicago. Similarly, if the Web server is in New Delhi, India, you will see its local time.

Test this Web service here: http://www.xemantex.com/consumeWebSvcDateTime.aspx.

There are two steps to creating a Web service using .NET (note that creating and consuming are two different things for a Web service).

  1. Create an .asmx file (call it dateTimeWebSvc.asmx).
  2. Write the required functions to accomplish business processes.

You will look into Step 2 before going to Step 1. Following is the code for a function to return the current date and time as a string:

<WebMethod()> Public Function currDateTime() As String
   Dim dateTimeStr As String
   Dim tZn         As TimeZone              'get the time zone
   Dim tZnNameStr  As String                'time zone name
                                            '(CST, EST, etc)
   tZn = System.TimeZone.CurrentTimeZone    'get name of time zone
   If tZn.IsDaylightSavingTime(Now) Then
      tZnNameStr = tZn.DaylightName
   Else
      tZnNameStr = tZn.StandardName
   End If
   dateTimeStr = "Current date and time at this web server's _
                  geographical location " & _
   "is- " & Now.ToString & " " & tZnNameStr
   Return dateTimeStr
End Function

About the Author
Prasad Kopanati is the Vice President of XemanteX Inc. http://www.xemantex.com, an internet company offering language related services for web users. You can reach him via email at team@xemantex.com.

Go to page: 1  2  3  4  Next

Downloads

  • WebServiceASPNET_src.zip - Source files for the project

    Tools:
    Add www.codeguru.com to your favorites
    Add www.codeguru.com to your browser search box
    IE 7 | Firefox 2.0 | Firefox 1.5.x
    Receive news via our XML/RSS feed







  • RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

    (You must be signed in to rank an article. Not a member? Click here to register)

    Latest Comments:
    Add WebService Behaviour dynamically? - madhucellulo (09/04/2008)
    Add WebService Behaviour dynamically? - madhucellulo (09/04/2008)
    Add WebService Behaviour dynamically? - madhucellulo (09/04/2008)
    Add WebService Behaviour dynamically? - madhucellulo (09/04/2008)
    All Browser Not Support this - Netweb (12/31/2007)

    View All Comments
    Add a Comment:
    Title:
    Comment:
    Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



    (You must be signed in to comment on an article. Not a member? Click here to register)

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Whitepapers and eBooks

    Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
    IBM Solutions Brief: Go Green With IBM System xTM And Intel
    HP eBook: Simplifying SQL Server Management
    IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
    Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
    Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
    Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
    Intel PDF: Quad-Core Impacts More Than the Data Center
    Intel PDF: Virtualization Delivers Data Center Efficiency
    Go Parallel Article: PDC 2008 in Review
    Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
    Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
    Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
      PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
    Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
    Go Parallel Article: Q&A with a TBB Junkie
    IBM Whitepaper: Innovative Collaboration to Advance Your Business
    Internet.com eBook: Real Life Rails
    IBM eBook: The Pros and Cons of Outsourcing
    Internet.com eBook: Best Practices for Developing a Web Site
    IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
    Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
    IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
    Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
    HP eBook: Guide to Storage Networking
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES