Web Services: basics of Web Services; interacting with web services

एक web service एक application को दूसरे को web के across call करने देता है, page to browser की बजाय machine to machine, structured messages exchange करते हुए ताकि किसी भी language में written programs data और functionality share कर सकें।

10 min read · 8 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Apps जो Apps से बात करते हैं

अब तक सब कुछ आपके server का एक human के browser से बात करना था। पर कभी-कभी एक program को दूसरे program से बात करनी पड़ती है। मान लीजिए college का mobile app FestConnect की events की list चाहता है, या एक partner site इन्हें दिखाना चाहती है। इन्हें एक HTML page नहीं चाहिए; इन्हें raw data चाहिए, अपने own तरीके से इस्तेमाल करने के लिए।

यही है जिसके लिए एक web service है: यह एक application को दूसरे को web के across call करने देता है और structured data exchange करने देता है, machine to machine। यह closing technical topic basics और आप एक के साथ कैसे interact करते हैं cover करता है।

Theory

एक Web Service क्या है

एक web service functionality को web पर expose करता है ताकि other programs (browser में लोग नहीं) इसे इस्तेमाल कर सकें। एक web page return करने की बजाय, यह structured data return करती है जिसे caller process कर सकता है।

Classically, caller और service HTTP के over SOAP नाम के एक protocol इस्तेमाल करते हुए XML messages exchange करते हैं। Service एक contract publish करती है, एक WSDL document, जो exactly describe करता है यह क्या operations offer करती है और ये कौन सा data लेते और return करते हैं, तो एक caller जानता है इससे कैसे बात करनी है। Defining trait: यह language-independent है। .NET में written एक web service Java, PHP, या किसी और चीज़ में written एक program से call हो सकती है।

Formula

Point Interoperability है

XML/SOAP messages और एक WSDL contract पर standardise क्यों करें? ताकि कोई भी platform service call कर सके। FestConnect की events service, .NET में written, एक Android app से Java में, एक website से PHP में, या किसी और .NET app से consume हो सकती है, क्योंकि ये सब HTTP के over same message format पर agree करते हैं।

इस cross-platform cooperation को interoperability कहा जाता है, और यही पूरी वजह है web services exist करती हैं: shared functionality जो care नहीं करता caller कौन सी language बोलता है।

Theory

एक Create और Consume करना

Classic ASP.NET में आप एक web service create करते हैं एक .asmx file की तरह: एक class जिसके callable methods [WebMethod] attribute से marked हैं। सिर्फ़ उस attribute वाले methods callers को exposed होते हैं।

एक web service consume (call) करने के लिए, एक client program इसमें एक reference add करता है। Tools service का WSDL पढ़ते हैं और एक proxy generate करते हैं: same methods वाला एक local stand-in object। Client फिर उन methods को call करता है जैसे ये local हों, और proxy behind the scenes request भेजने और response receive करने को handle करता है। एक remote service के साथ interact करना आख़िरकार एक ordinary method call करने जैसा दिखता है।

Practical

A tiny FestConnect web service, and calling it

// CREATE: expose a method other programs can call (in an .asmx service)
public class EventsService : System.Web.Services.WebService
{
    [WebMethod]                       // this attribute makes it callable
    public string[] GetEventNames()
    {
        return new[] { "Robotics Workshop", "Coding Contest", "Music Night" };
    }
}

// CONSUME: after adding a reference, a client calls it like a local method
// var svc = new EventsService();
// string[] names = svc.GetEventNames();   // proxy handles the web call

Quiz

एक web service का defining purpose क्या है?

  1. Human visitors को nicely styled HTML pages display करना
  2. दूसरे programs को इसे web के over call करने देना और structured data exchange करना, इनकी language या platform से independent
  3. एक application के लिए connection string store करना
  4. Database को एक XML file से replace करना
Show the answer

दूसरे programs को इसे web के over call करने देना और structured data exchange करना, इनकी language या platform से independent

एक web service functionality को web पर OTHER PROGRAMS के consume करने के लिए expose करती है, structured data (classically XML/SOAP) एक language-independent तरीके से exchange करते हुए, तो एक .NET service Java, PHP, या किसी भी platform से call हो सकती है। Option A humans के लिए बनाए ordinary web pages describe करता है; एक web service programs serve करती है, browsers नहीं, और data return करती है, styled HTML नहीं। Option C इसे web.config से confuse करता है, जो settings hold करता है। Option D wrong है: एक web service एक data store नहीं है और database replace नहीं करती; यह एक interface है जिसे दूसरे applications call करते हैं। Key idea languages और platforms के across machine-to-machine interoperability है।

Think first

Database सिर्फ़ Share करने की बजाय एक Web Service क्यों Expose करें?

अगर एक partner app FestConnect के events चाहता है, database को सीधा access क्यों न दें? फिर tap कीजिए।

Show the answer

क्योंकि एक web service आपको एक controlled, stable, safe INTERFACE देती है, जबकि direct database access बहुत ज़्यादा दे देती है। अगर आप एक partner को अपने database credentials handed करें, ये आपका पूरा schema देखेंगे, ऐसा data पढ़ या यहाँ तक कि बदल सकते हैं जो आपने कभी share करने का मतलब नहीं रखा, और आपका app इनका तोड़ देगा जिस moment आप एक table rename करें। एक web service सिर्फ़ वे specific operations expose करती है जो आप चुनते हैं, मान लीजिए GetEventNames, और कुछ नहीं; caller कभी आपके tables को touch नहीं करता, आपकी internal structure नहीं देखता, या आपका database password hold नहीं करता। आप service के पीछे validation, security, और rules add कर सकते हैं, और आप अपना database freely restructure कर सकते हैं जब तक service का contract (इसका WSDL) same रहे। यह language-independent भी है, तो कोई भी platform इसे call कर सकता है, जबकि एक raw database connection callers को specific drivers और credentials से tie करता है। Short में, एक web service एक deliberate front door है: यह exactly वह share करती है जो आप चाहते हैं, safely और stably, पूरी building की keys handover करने की बजाय। एक interface expose कीजिए, अपने internals नहीं।

Summary

Key takeaways

  • एक web service एक application को दूसरे को web के across call करने देता है, machine to machine, browser को pages serve करने की बजाय।
  • यह functionality दूसरे programs को expose करता है और structured data return करता है, classically SOAP के through HTTP पर XML messages।
  • एक WSDL document service का contract है, इसके operations और इनके data describe करते हुए तो callers जानें इसे कैसे इस्तेमाल करें।
  • Web services language-independent हैं: एक .NET service Java, PHP, या किसी भी चीज़ से call हो सकती है, interoperability enable करते हुए।
  • Classic ASP.NET में आप एक service को [WebMethod] से marked methods वाली एक .asmx file की तरह create करते हैं; सिर्फ़ वे callable हैं।
  • एक client एक reference add करके एक service consume करता है; एक generated proxy इसे remote methods को local जैसे call करने देता है।
  • Memory hook: एक web service programs के लिए एक safe front door है, किसी भी language के across data share करते हुए।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Advance ASP.NET

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Web Services: basics of Web Services; interacting with web services · .NET Technology (Major-13) · Gri-Learn