XML Web Services. Technology overview

The topic title is really a question, since I myself do not know what it is and for the first time I will try to work with it within the framework of this article. The only thing I can guarantee that the code below will work, but my phrases will be just assumptions and guesses about how I myself understand all this. So let's go ...

Introduction

We need to start with what the concept of web services was created for. By the time this concept appeared, technologies already existed in the world that allowed applications to interact at a distance, where one program could call some method in another program, which could be run on a computer located in another city or even a country. All of this is abbreviated as RPC (Remote Procedure Calling). Examples include CORBA technologies, and for Java - RMI (Remote Method Invoking). And everything seems to be good in them, especially in CORBA, tk. you can work with it in any programming language, but something was still missing. I believe that the disadvantage of CORBA is that it works through some of its own network protocols instead of simple HTTP, which will crawl through any firewall. The idea behind the web service was to create an RPC that would stick into HTTP packets. This is how the development of the standard began. What are the basic concepts of this standard:
  1. SOAP... Before calling a remote procedure, you need to describe this call in a SOAP XML file. SOAP is simply one of the many XML markups used in web services. Everything that we want to send somewhere via HTTP is first turned into an XML SOAP description, then it is put into an HTTP packet and sent to another computer on the network via TCP / IP.
  2. WSDL... There is a web service i.e. a program whose methods can be called remotely. But the standard requires that a description be attached to this program, which says that "yes, you are not mistaken - this is really a web service and you can call such and such methods from it." This description is represented by another XML file that has a different format, namely WSDL. Those. WSDL is just an XML description file for a web service and nothing else.
Why do you ask so briefly? Can't you get more details? Probably you can, but for this you have to turn to books like Mashnin T. "Java Web Services". There, for the first 200 pages, there is a detailed description of each tag of the SOAP and WSDL standards. Should I do it? In my opinion, no, tk. all of this is generated automatically in Java, and all you need to do is write the contents of the methods that are supposed to be called remotely. So, in Java there was such an API as JAX-RPC. If anyone does not know, when they say that Java has such and such an API, it means that there is a package with a set of classes that encapsulate the technology in question. JAX-RPC evolved from version to version for a long time and eventually evolved into JAX-WS. WS obviously stands for WebService and you might think that this is a simple renaming of RPC into a popular word these days. This is not the case, since Now web services have moved away from the original idea and allow you not only to call remote methods, but also to simply send document messages in SOAP format. Why this is needed, I do not know yet, the answer is unlikely to be "just in case, suddenly it will be needed." I myself would like to learn from more experienced comrades. And the last thing, then there was also JAX-RS for the so-called RESTful web services, but this is a topic for a separate article. At this point, the introduction can be ended, because next we will learn to work with JAX-WS.

General approach

Web services always have a client and a server. The server is our web service and is sometimes called an endpoint (like the endpoint where SOAP messages from the client go). We need to do the following:
  1. Describe the interface of our web service
  2. Implement this interface
  3. Start our web service
  4. Write a client and call the required web service method remotely
A web service can be launched in different ways: either by describing a class with a main method and launching the web service directly, as a server, or deploying it to a server like Tomcat or any other. In the second case, we ourselves do not start a new server and do not open another port on the computer, but simply tell the Tomcat servlet container that “we wrote the web service classes here, publish them, please, so that everyone who contacts you can our use the web service ". Regardless of the method of launching the web service, we will have the same client.

Server

Let's start IDEA and create a new project Create New Project... Let's enter a name HelloWebService and press the button Next, then the button Finish... In the folder src create a package ru.javarush.ws... In this package, we will create the HelloWebService interface: package ru. javarush. ws; // these are annotations, i.e. a way to mark our classes and methods, // as related to web service technology import javax. jws. WebMethod; import javax. jws. WebService; import javax. jws. soap. SOAPBinding; // we say that our interface will work as a web service@WebService // say that the web service will be used to call methods@SOAPBinding (style = SOAPBinding. Style. RPC) public interface HelloWebService ( // we say that this method can be called remotely@WebMethod public String getHelloString (String name); ) In this code, the WebService and WebMethod classes are so-called annotations and do nothing but mark our interface and its method as a web service. The same is true for the SOAPBinding class. The only difference is that SOAPBinding is a parameter annotation. In this case, the style parameter is used with a value that says that the web service will work not through document messages, but as a classic RPC, i.e. to call the method. Let's implement the logic of our interface and create a HelloWebServiceImpl class in our package. By the way, I note that the end of the class in Impl is a convention in Java, according to which the implementation of interfaces is denoted in this way (Impl - from the word implementation, i.e. implementation). This is not a requirement and you are free to name the class whatever you want, but the rules of good form require it: package ru. javarush. ws; // the same annotation as when describing the interface, import javax. jws. WebService; // but used here with endpointInterface parameter, // specifying the fully qualified class name of the interface of our web service@WebService (endpointInterface = "ru.javarush.ws.HelloWebService") public class HelloWebServiceImpl implements HelloWebService (@Override public String getHelloString (String name) ( // just return a greeting return "Hello," + name + "!" ; )) Let's start our web service as an independent server, i.e. without the involvement of any Tomcat and application servers (this is a topic for a separate discussion). To do this, in the project structure in the folder src let's create a package ru.javarush.endpoint, and in it create a HelloWebServicePublisher class with a main method: package ru. javarush. endpoint; // class to start a web server with web services import javax. xml. ws. Endpoint; // class of our web service import ru. javarush. ws. HelloWebServiceImpl; public class HelloWebServicePublisher (public static void main (String... args) ( // start the web server on port 1986 // and at the address specified in the first argument, // start the web service passed in the second argument Endpoint. publish ( "http: // localhost: 1986 / wss / hello", new HelloWebServiceImpl ()); )) Now let's run this class by clicking Shift + F10... Nothing appears in the console, but the server is running. You can verify this by typing in the browser the line http: // localhost: 1986 / wss / hello? Wsdl. The page that opens, on the one hand, proves that a web server (http: //) has started on our computer (localhost) on port 1986, and, on the other hand, shows the WSDL description of our web service. If you stop the application, the description will become inaccessible, as well as the web service itself, so we will not do this, but proceed to writing the client.

Customer

In the project folder src create a package ru.javarush.client, and in it the HelloWebServiceClient class with the main method: package ru. javarush. client; // needed to get wsdl description and through it // reach the web service itself import java. net. URL; // such an execution will occur when working with a URL object import java. net. MalformedURLException; // classes to parse xml-ku with wsdl description // and reach the service tag in it import javax. xml. namespace. QName; import javax. xml. ws. Service; // the interface of our web service (we need more) import ru. javarush. ws. HelloWebService; public class HelloWebServiceClient (public static void main (String args) throws MalformedURLException ( // create a link to wsdl description Url url = new url ( "http: // localhost: 1986 / wss / hello? wsdl") ; // We look at the parameters of the next constructor in the very first tag of the WSDL description - definitions // see the 1st argument in the targetNamespace attribute // see the 2nd argument in the name attribute QName qname = new QName ("http: //ws.site/", "HelloWebServiceImplService"); // Now we can reach the service tag in the wsdl description, Service service = Service. create (url, qname); // and then up to the nested port tag, so that // get a link to a web service object remote from us HelloWebService hello = service. getPort (HelloWebService. class); // Hooray! Now you can call the remote method System. out. println (hello. getHelloString ("CodeGym")); )) I gave maximum comments on the code in the listing. I have nothing to add, so run (Shift + F10). We should see the text in the console: Hello, CodeGym! If you didn't see it, you probably forgot to start the web service.

Conclusion

In this topic, a brief excursion into web services was presented. Again, a lot of what I've written is my guesswork as to how it works, and therefore shouldn't be trusted too much. I would be grateful if knowledgeable people correct me, because then I will learn something. UPD.

Web service (service) - a program that organizes interaction between sites. Information from one portal is transferred to another.

For example, there is an airline. She has a lot of flights, respectively, a lot of tickets. It transmits information through a web service to a travel aggregator site. A user who visits the aggregator will be able to buy tickets for this airline right there.

Another example of web services is a weather tracking site that contains information about the weather conditions in a particular city or country as a whole. This information is also often used by third parties.

Information on the Internet is diverse. Websites are managed by different systems. different transmission and encryption protocols are used. Web services make it easy to exchange information between different sites.

Web services architecture and protocols

You can define 3 instances that interact with each other: the catalog, the contractor and the customer. After creating a service, the contractor registers it in the catalog, and there the customer finds the service.

The data exchange mechanism is formed in the description of the Web Services Description. It is a specification that covers transport formats, content types, transport protocols that are used in the exchange of information between a customer and a service carrier.

Today, several technologies are most often used to implement various web services:

  1. TCP / IP is a protocol that is understood by almost any network equipment, from mainframes to portable devices and PDAs.
  2. HTML is a general-purpose markup language used for displaying content on consumer devices.
  3. XML is a universal tool for processing all kinds of data. Other information exchange protocols can work on its basis: SOAP and WSDL.
  4. UDDI is a universal source of recognition, integration and description. Works, as a rule, in private networks and has not yet found sufficient distribution.

The versatility of the presented technologies is the basis for understanding web services. They run on standard technologies that are independent of application vendors and other network resources. Can be used on any operating system, application server, programming language, etc.

Advantages

  • Creation of the necessary conditions for the interaction of software components regardless of the platform.
  • Web services are based on open standard protocols. Due to the introduction of XML, the simplicity of the formation and configuration of web services is provided.
  • The use of HTTP guarantees interoperability between systems through network access.

Flaws

  • Low performance and high traffic volume, in comparison with RMI, CORBA, DCOM systems, due to the use of XML-messages in the context of text.
  • Security level. All modern web services must implement coding and require user authorization. Whether HTTPS is enough here or more reliable protocols like XML Encryption, SAML, etc. are needed is a matter of development.

Web services tasks

Web services can be used in many areas.

B2B transactions

The processes are integrated immediately, without the participation of people. For example, replenishment of the catalog of an online store with new products. They are brought to the warehouse, and the storekeeper records the arrival in the database. Information is automatically transmitted to the online store. And the buyer, instead of marking “Out of stock” on the product card, sees its quantity.

Enterprise Service Integration

If the company uses corporate programs, then the web service will help to set up their collaboration.

Creation of a client-server system

Services are used to customize how the client and server work. This provides the following benefits:

  • you can sell not the software itself, but pay for access to the web service;
  • easier to solve problems using third-party software;
  • easier to organize access to content and materials on the server.

A web service is an application that simplifies the technical configuration of resource interactions.

Today WEB services are used almost everywhere - they provide us with information about flights of airplanes and trains, exchange rates and weather. It is not surprising that 1C also has the ability to create its own WEB services that allow it to act as both a supplier and a consumer. This mechanism is built into the 1C: Enterprise 8.3 platform and developers can even add their own WEB services objects to the standard configuration. Their architecture is built on a set of services that allow information to be exchanged with other software.

Creation of a 1C web service

One of the main advantages of 1C WEB services is the absence of the need to provide direct access to information security data. A properly configured 1C web service allows other applications to use functions from the outside. In such cases, the function itself should determine the right to use the data according to the specified parameters according to the rules prescribed by the developer.

How to create a web service in 1C?

In order for a certain function of the 1C system to become available to external software, the following sequence of actions must be performed:

  1. Go to the configuration and add a WEB-service object in a specific branch of the tree;
  2. Describe all the operations that our functionality can perform. Description of functions is made in the module in the language built into 1C;
  3. Add a description of the parameters of the web service functions. Please note that data types are described taking into account the existing types of the XDTO mechanism that appeared in the platform version 8.1;
  4. Publish the created WEB service on the server. The mechanism built into the 1C platform supports the following standards:
  • SSL / TLS
  • WS-I BP

An example of creating a simple WEB service

In order to most clearly demonstrate the operation of the WEB-services mechanism, let's create an example - a functional that determines the length of the entered string. The software will pass a string as a query parameter, and the function described in 1C will return the number of characters. When creating, you need to remember that the publication of this mechanism will make it possible for various software to access it. Since not every software is able to perceive the Cyrillic alphabet, we will name the configuration objects using Latin characters.

Open the configurator, find the "WEB-services" branch in the tree and add a new service "wa_LengthString". It is also necessary to add a new operation on the Operations tab. Let's call it "CalcLengthString", in the properties, specify the type of the return value - int or integer and create the "InputString" parameter inside it. We leave the value type as string.


Now you need to register the action of the CalcLengthString function in the WEB service module. To do this, open the properties of the created function and click the magnifying glass button on the right next to the "Procedure name" input field. 1C will automatically create a function in the module of our WEB service and open it so that we can describe the CalcLengthString action. Let's take advantage of this and write the action of the function - determining the length of the input string.


In fact, this completes the creation of the simplest WEB-service. Now you need to "put" this service in the public domain so that third-party software or other 1C systems can use this functionality.

In order for us to be able to publish the created web service with its functionality, we need to have access to the site. Before we start publishing the service, we need to check the file name in the properties of the newly created wa_LengthString module. It should be clear, simple and have the "1cws" extension.


Now it's time to publish the WEB service we created on the server. This feature appeared in version 8.3 of the platform, and many companies have already understood the full benefits of this functionality. In order to start publishing, you need to open the "Administration / Publishing on the web server ..." form in the configurator.


In the window that opens, we need to configure 1C Web services and fill in certain fields:

  • Name. Indicates a folder on a web server that will store a description of our web service. Be careful about case, as sometimes servers distinguish between uppercase and lowercase characters;
  • Web server. You must select a server from those installed on the computer;
  • Catalog. You must select the path to the folder where the web server data for setting up the connection is stored. Only Latin letters are used;
  • Two signs of the "Boolean" type. The first is useful for us if we need to configure access through the web client to the configuration. In order to publish the 1C service, you need to put the second mark.

It remains only to check that the required WEB-service has a checkbox in the first column, and click on "Publish".


Since this mechanism is still quite new, you may encounter an error of the form "An error occurred while performing a file operation ...". In this case, you just need to repeat the "Publish" button. In most cases, this helps, and you will be presented with a message that the web service has been published.

Ru // ws / .1cws? Wsdl

In response to such a request for an address, the browser should display the structure of the XML file. If you see a blank page, an error or incomprehensible characters (encoding problems), then you need to check all the actions again. It will also not be superfluous to make sure that the server is configured correctly and you have access to it. After successful publication, 1C WEB service will be able to use third-party applications.

WEB-service - (from English web-service, synonym - online service). Web services are understood as services that are provided on the Internet using special programs. For example, such services as: hosting, e-mail, storage of various information (files, bookmarks) on the Internet, calendar, etc. are common. An important property of a web service is that it does not depend on your provider, computer or browser - you can work with your data anywhere in the world where you have access to.

Knyazev A.A. Encyclopedic Dictionary of Media. - Bishkek: Publishing house of KRSU... A. A. Knyazev. 2002.

See what "WEB-service" is in other dictionaries:

    Web service

    Web service- Web service. Web service, web service is a software system identified by a string; interfaces are defined in XML and transmitted using Internet protocols. A web service is a unit of modularity when used ... ... Wikipedia

    Web Cache Communication Protocol- (WCCP) Cisco's Content Redirection Protocol. Provides a mechanism to redirect traffic streams in real time. Has built-in scaling, load balancing, fault tolerance. Cisco IOS ... ... Wikipedia

    Web Map Service- (WMS rus. Web map service) a standard protocol for servicing georeferenced images via the Internet, generated by a cartographic server based on data from a GIS database. This standard was developed and for the first time ... ... Wikipedia

    Web Hotel Salvador- (Salvador, Brazil) Hotel Category: 2 Star Hotel Address: Rua das Alfazemas… Hotel Directory

    Web Hotel Aparecida- (Aparecida, Brazil) Hotel Category: 3 Star Hotel Address: Av. Isaac Ferrei… Hotel directory

    service oriented architecture- The business processes of the organization are implemented on the basis of the services provided by the existing applications of the Customer. If applications do not support the ability to provide services (Web Services), when the product is deployed ... ... Technical translator's guide

    Web 2

    Web 2.0- Key Concepts Associated with Web 2.0 Web 2.0 (as defined by Tim O'Reilly) is a method of designing systems that, by accounting for network interactions, get better the more people use them. Feature of web 2.0. is the principle ... ... Wikipedia

    Website- Request "site" is redirected here. Cm. also other meanings. A web site (from the English Website: web web and site "place") in a computer network united under one domain name or IP address) is a collection of documents of a private person or ... ... Wikipedia

Books

  • Information technology in the tourism industry, V. N. Shitov. The manual discusses in detail general-purpose computer technologies using popular Microsoft Office 2010 packages and alternative complexes, the use of ... Buy for 546 rubles
  • 75 ready-made solutions for your Web site in PHP, Steinmetz U., Ward B .. Everyone who makes or is going to make his own website inevitably faces a number of tasks and difficulties: how to make a blog on the site ... .... "screw up" the vote, close certain ...

Based on the web service architecture, we create the following two components as part of the web services implementation:

Service provider or publisher

This is a web service provider. A service provider implements this service and makes it available on the Internet or intranet. We will be writing and publishing a simple web service using the .NET SDK.

Service provider or consumer

Any consumer of a web service. The requester uses an existing web service by opening a network connection and submitting an XML request. We will also write two requests for web services: one web consumer (ASP.NET application) and another consumer based on Windows applications.

Below is our first example of a web service that acts as a service provider and provides two methods (add and SayHello) as web services to be used by applications. This is the standard template for a web service. The .asmx extension is used in NET services. Note that a method exposed as a web service has a WebMethod attribute. Save this file as FirstService.asmx in the IIS virtual directory (as described in setting up IIS, for example c: \ MyWebSerces).

FirstService.asmx

<%@ WebService language = "C" class = "FirstService" %>using System; using System.Web.Services; using System.Xml.Serialization; public class FirstService: WebService (public int Add (int a, int b) (return a + b;) public String SayHello () (return "Hello World";))

To test a web service, it must be published. The web service can be published either on the intranet or on the Internet. We will publish this web service to IIS running on a local machine. Let's start by setting up IIS.

  • Open "Start" → "Settings" → "Control Panel" → "Administrative Tools" → "Internet Service Manager".
  • Expand and right-click the default website; select "New" → "Virtual Directory". The New Virtual Directory Wizard will open. Click Next.
  • The "Virtual Directory" screen appears. Enter the name of the virtual directory. For example, MyWebServices. and click Next.
  • The "Website Content Directory" screen appears.
  • Enter the directory name for the virtual directory. For example, c: \ MyWebServices Click Next.
  • The "Access Authorization" screen appears. Change the settings as per your requirement. Let's keep the default settings for this exercise.
  • Click "Next". It completes the IIS configuration.
  • Click Finish to complete the setup.

To check if IIS is configured correctly, copy the HTML file (such as x.html) to the virtual directory (C: \ MyWebServices) created above. Now open Internet Explorer and enter http: //localhost/MyWebServices/x.html. It should open the x.html file.

Note... If that doesn't work, try replacing localhost with your device's IP address. If it still doesn't work, check if IIS is running; you may need to reconfigure IIS and the virtual directory.

To test this web service, copy FirstService.asmx to the IIS virtual directory created above (C: \ MyWebServices). Open the web service in Internet Explorer (http: //localhost/MyWebServices/FirstService.asmx). It should open the web service page. The page should link to two methods that we provide as web services in our application. Congratulations! You've written your first web service!

Testing the web service

As we just saw, it is easy to write web services in the .NET Framework. Writing web services is also easy in .NET; however, it is a little more active. As stated earlier, we will be writing two types of service consumers: one website and another user based on Windows applications. Let's write our first web service consumer.

Web services

Write a web consumer like below. Call it WebApp.aspx. Please note that this is an ASP.NET application. Save this in the web service virtual directory (c: \ MyWebServices \ WebApp.axpx). This app has two text boxes that are used to get numbers from the user to add. It has a single Run button that, when clicked, gets the Add and SayHello web services.

WebApp.axpx

<%@ Page Language="C#" %>

First Number to Add: 4< /asp:TextBox>

Second Number To Add: 5

Web Service Result -

Hello world service : Label< /asp:Label>

Add Service : & Label

After creating the consumer, we need to create a proxy to consume the web service. This work is done automatically by Visual Studio .NET for us when referencing the added web service. Here are the steps to follow:

  • Create a proxy to use the web service. The proxy is created using the WSDL utility provided with the .NET SDK. This utility extracts information from a web service and creates a proxy server. The proxy is only valid for a specific web service. If you need to use other web services, you also need to create a proxy for that service. Visual Studio .NET automatically creates a proxy when a web service reference is added. Create a proxy for the web service using the WSDL utility provided with the .NET SDK. It will create a FirstSevice.cs file in the current directory. We need to compile it to create the FirstService.dll (proxy) for the web service.
  • c:> WSDL http: //localhost/MyWebServices/FirstService.asmx? WSDL
  • c:> csc / t: library FirstService.cs
  • Place the compiled proxy in the bin directory of the web service virtual directory (c: \ MyWebServices \ bin). Internet Information Services (IIS) searches this directory for a proxy server.
  • Create a service consumer just like us. Note that the web service proxy object is created on the consumer. This proxy server takes care of the interaction with the service.
  • Enter the consumer URL in IE to test it (for example, http: //localhost/MyWebServices/WebApp.aspx).

Windows Application-Based Web Services Consumer

Writing a web service application based on Windows applications is like writing any other Windows application. You only need to create a proxy (which we already did) and reference this proxy when compiling your application. Below is our Windows application that uses the web service. This application creates a web service object (proxy, of course) and calls the SayHello and Add methods on it.

WinApp.cs

using System; using System.IO; namespace SvcConsumer (class SvcEater (public static void Main (String args) (FirstService mySvc = new FirstService (); Console.WriteLine ("Calling Hello World Service:" + mySvc.SayHello ()); Console.WriteLine ("Calling Add ( 2, 3) Service: "+ mySvc.Add (2, 3) .ToString ());)))

Compile it with c: \> csc /r:FirstService.dll WinApp.cs. It will create a WinApp.exe file. Run it to test your app and web service.

Now the question is, how can you be sure that this application is actually calling the web service?

It's easy to check. Stop your web server so that the web service cannot be contacted. Now start the WinApp application. It will throw an exception at runtime. Now start the web server again. It should work.