Development Web Services SOAP

  1. What is a web service?
    Think of a web service as a function call to a remote server which offers some specific functionality. This exchange occurs over the HTTP protocol and the resulting request results in XML/JSON object data being returned, parsed, and used by the consuming client to show a map (Google Maps), or provide the weather (Yahoo Weather), or give a stock quote (NYSE Ticker). They key is that this data exchange occurs using XML/JSON and can occur anywhere in the world and across different systems.
  2. How do you deploy a web service?
    Web service, once created, generates several files which are then treated much like how a website is published. In IIS | Add Application using name (ie, MyFirstWebService) and path (ie, C:\Sites\MyWebService). Finally, view it by selecting Browse | Service.asmx. Test it by following link and entering parameters and if successful, result in a return of the result in XML/JSON format. Optionally, in the UI, you can right click BROWSE of the .asmx file and view it here as well.
  3. Quickly, explain SOAP vs REST.
    REST is an architecture. REST will give human-readable results. REST is stateless. REST services are easily cacheable and is smaller and faster than SOAP. SOAP is a protocol. It can run on top of other protocols such as SMTP, FTP, HTTP, etc.
  4. What are the parts of a basic SOAP message?
    An envelope which includes a header and a body.
  5. What files get created when you build a simple Math web service in .NET called MyWebService?
    • (a) *.dll file in bin directory
    • (b) *.asmx for viewing/testing
    • (c) *.cs file which has all functions
    • (d) 
    • (e) web.config
    • (f) global.asax
  6. What name space do you use for a web service?
    Using System.Web.Services;
  7. Do web services use inheritance?
    Yes, ANY class contained in a web service must inherit from the WebService class, for example, public class MyWebService: WebService.
  8. Web services can contain important, proprietary data and business logic. Since they are accessible and searchable by anyone on the web, how do you prevent others from seeing this information?
    All web services are accessible from the web, so security must be handled by the service itself and this is done two ways: private functions and public functions. Those that are public should handle their own security to determine if they want to send something back to calling procedure (ie, if not, perhaps use a key and session variables to maintain proper access)
  9. What is REST?
    REST stands for REpresentational State Transfer which, unlike SOAP, is not a protocol but an architectural style.
  10. What is SOAP?
    Simple Object Access Protocol (SOAP) is a strongly-typed XML based messaging protocol created by Microsoft and largely replaced by REST. SOAP is a way for a program running in one kind of OS to communicate with a program in the same or different OS using HTTP and XML. Developed by Microsoft, it specifies exactly how to encode an HTTP header and XML file so that communication between two systems can occur. As an example, a SOAP message could be sent to a website with various parameters (city name, zipcode, price, home size) for a search. The site would then process the requests and return an XML-formatted document with resulting data (prices, locations, features, etc.). With this information being returned back, the original party could parse this information for display to the user. Examples would include Google Weather, Analytics, an RSS Feed, or Zillow.
  11. Which is a better to use, REST or SOAP services?
    Depends on the objective. SOAP is more heavy-duty, can be used on multiple systems such as HTTP, TCP, SMTP and others, is strongly-typed, can have state implementation details, and is standardized so has better adoption across firewalls, proxies, and other standardized implementations. REST is smaller and simpler to use, has been adopted over SOAP in most applications, works well on mobile devices and PDA's, is stateless, is not type-safe, can output XML or other languages.
  12. Once a web service has been created, how would you call it from another application?
    In the Project icon, you would select 'Add Web Reference' and supply the necessary URL to the new web service which you will now call MyService.

    • Finally, in the code behind, you would need to create two lines of code:
    • (1) MyService.Service1 service = new MyService.Service1();
    • (b) string message = service.HelloWorld();
  13. Write a super simple web service that displays 'Hello World', starting from namespace.
    • using System;
    • using System.Web.Services;

    • namespace WebServiceExample
    • {
    •      public class MyWebService: System.Web.Service.WebService
    •      {
    •           public string HelloWorld(){return "Hello World"; }
    •      }
    • }
  14. When testing a web service on a local machine (hence, not having no external http address), how to we can the URL?
    • We use the localhost keyword.
    • For exampe: http://localhost/MathService/MathService.asmx
  15. How do you test a web service?
    Open the .asmx file in a browser which will show all public methods and parameters (if there are any). Then select the INVOKE button to see the resulting XML/JSON.
  16. How would you consume a simple web service in C#?
    • MyService.Service1 service = new MyService.Service1();
    • string message = service.HelloWorld();
  17. What's the advantage of using a web service over other methods such as just getting the data directly from the webpage/database?
    • (a) because we are using either XML/JSON then we are dealing ONLY with data 
    • (b) Data exchange can occur between two dissimular systems (ie, Apple, Windows, or a Android Phone
    • (c) Anywhere in the world since it uses HTTP requests which is used by the entire WWW.
  18. Can you return JSON and XML in a web service?
    Yes, of course. Below are two example web services which return major world city objects in XML/JSON.

    • (a)
    • (b)
Card Set
Development Web Services SOAP
Software Development Web Services SOAP