Working with Terrasoft Web services from external applications. Web services We accept a file by web service 1c


Keywords: web service, web service, SOAP, WSDL, ws link

Disclaimer and terms of use

All trademarks accidentally mentioned in this article belong to their respective owners.
This article is published under the Creative Commons Attribution-Share Alike 3.0 Unported License. http://creativecommons.org/licenses/by-sa/3.0/

Another disclaimer (after many times)

The 1C:Enterprise 8 platform is constantly evolving. In this connection, the code presented in this article will generate an error in the latest versions of the platform. This happens, in particular, due to the fact that the order of calling the methods of the web service proxy object has changed: for example, complex objects must be explicitly converted to an XDTO Object of the corresponding type using the Factory of the corresponding service. You can read about this on our forum or in the book "1C: Enterprise Integration Technologies" http://v8.1c.ru/metod/books/book.jsp?id=288

Introduction

When it appears a new version some software product, then naturally, first of all, I want to understand what is new in it. In the case of "1C:Enterprise 8.1", web services became such a new "feature" for me. A lot has been written and said about web services, since this technology has existed by computer standards for a long time. Therefore, I will not repeat myself, I send everyone to Yandex for information. Let me just say that with the release of the new edition of the 1C:Enterprise 8.1 platform, 1Snikov has the opportunity to create and use web services technology, being, so to speak, in their native environment. In this article, I want to show you how to use external web services in your developments.

For those who are completely "out of touch": about web services "on the fingers"

OK, specially for you I will try to tell a little what a web service is, and why exactly This It seemed to me such a "delicious" innovation of the platform. Perhaps you know about COM technology or heard something about OLE? Sooner or later, any one-man will encounter this technology (especially if you need to quickly transfer some directory "Employees", and the personnel department, foreseeing the need to drive in all 1500 employees again, is ready to hang you on the first suitable nail).
Yes, and so, at the heart of COM technology is the idea of possibilities calling program code (and accessing data) of one application from another application. Moreover, possibilities do this not at the level of individual procedures and functions, but by getting at the disposal objects another application. When using OLE, we create an object in our application that is " representative" or, if you prefer, " wrapper" some object of the application with which we want to establish interaction (the so-called "OLE-object" or "COM-object"). Through this "wrapper" object, the properties and methods of the object of another application become available to us, and only those of which the developer Togo applications allowed us to use by publishing them in the description interface. (Well, I didn’t want to get into the jungle, but it doesn’t work in another way ...)
Now let's imagine that the same the application is on another computer, and not even in local network(DCOM, CORBA and other abbreviations do a good job with such cases), and somewhere far, far away on the Internet. This is where web services come on the scene (also complete with abbreviations: SOAP, WSDL, etc.), which allow you to do a similar "trick" in this case: i.e. receive data and manipulate objects of an application running on a computer on the other side of the Internet.
Under " external"by a web service, I will understand a web service provided by some supplier service (that is, not our application.) Accordingly, under "internal" - a web service that we will provide from, or more precisely, based our application. When using external web services, you need to understand that although the "wrapper" object is created in our "local" application, the "executing code" of this object is, perhaps, on the other side of the globe. However, the exchange between us And them takes place on the now ubiquitous XML, with its well-known "pluses" (universality and structuredness) and "minuses" (bloat), and good old http is used as a "transmission line".
Oh, and don't forget about internet traffic! Moreover, in the case of external web services, most of it will have to incoming component.
Everything else is in Yandex. Let's go further...

Where are the legs from, i.e. wings grow

Having rummaged in the same Yandex, I found a wonderful web service from the Aeroflot company, which allows you to receive real-time information about the arrival and departure of aircraft, and decided to make a kind of "Airport Display" in "1C: Enterprise". The service itself lives here: http://webservices.aeroflot.ru/desc_flightinfo.asp

He said, "Let's go!"

To begin with, I created an empty "1C:Enterprise 8.1" configuration (at the time of this writing, I had the platform version 8.1.5.123 at my disposal). Then I added a new object of type WS-reference to my configuration. To the proposed request to enter the URL of the imported WSDL, I entered a link to the WSDL file, which is listed on the service page: http://webservices.aeroflot.aero/flightstatus.wsdl (WSDL file is a description of the web service. For details, see Yandex ), and proudly named the created object "Aeroflot". By double-clicking on this object, I got a tree with the structure of the web service.

This tree is a "portrait" of the web service as 1Ska sees it. The most interesting is in the "Web services" branch: this names And ports web services (in fact, a WSDL file can describe not one, but several web services, then a separate branch will be created for each web service), and listed methods web service. These are the very "threads" by pulling which you can slightly open access to the data provided by the web service. The "Data Model" branch contains a description of the data type libraries that are used by the web service.
Brief information about using the web service can usually be found in the same place as the link to the WSDL file. In the case of Aeroflot, this is the page http://webservices.aeroflot.aero/flightstatus.asmx

"Taking off, then landing..."

To work with the web service, I added the processing of "Scoreboard" to the configuration, and in it - one form, which I assigned as the main one. On the form I put the "SelectAirport" selection field, the "DateFlight" input field, the "Scoreboard" panel with two pages "Arrival" and "Departure", while I unchecked the "Distribute by pages" flag in the panel properties, and the table field "TableScoreboard ".
Interaction with the web service occurs on the "request-response" principle, while a special intermediary object is created for the web service. That's why I added an attribute of the "Aeroflot Service" form of an arbitrary type.
If you carefully read the description of the service, you can see that the web service provides data on arrivals and departures through calls to the Arrival and Departure methods, respectively. In this case, both methods take the airport code and the desired date as parameters. In addition, the web service provides an opportunity to get a list of airports for which data is available in the system. The following scenario of interaction with a web service is quite obvious:
1. Get a list of airports;
2. Select the desired airport and date;
3. Get data on arrivals or departures;
But before accessing the web service, you need to initialize the proxy object (of type WSProxy), which I did in the form open handler:
Aeroflot Service=WSLinks.Aeroflot.CreateWSProxy(" http: //www.aeroflot.ru/", "FlightStatus", "FlightStatusSoap");
The first parameter is the namespace URI of the web service. You can find it out by opening the properties of the web service in the WS link tree. The second and third parameter parameters are the name and port of the web service, respectively.
(do not confuse the concepts of "name", "port", "proxy", etc. as applied to web services with the more familiar concepts of the TCP / IP protocol. If there is a correspondence between them, it is rather semantic. In the general case you need to understand that, for example, a web service port and a TCP port are completely different things).
Thus, I initialized the Aeroflot Service object of the WSProxy type, which is essentially a "wrapper" of the web service. Through it, I can access the methods of the web service as "native" methods of the platform.
First of all, I got a list of airports and filled in the list of the "SelectAirport" select field:

ChoiceList=FormItems.AirportChoice.ChoiceList; ChoiceList.Clear(); AirportList=ServiceAeroflot.AirportList().GetList("list "); TotalAirports=ListAirports.Number(); For ii=0 by TotalAirports-1 Loop Airport=ListAirports.Get(s); ChoiceList.Add(Airport.code, ""+Airport.city+" : "+Airport.name); EndCycle;
Here we need a small comment on the designAirportList=ServiceAeroflot.AirportList().GetList("list");
The thing is that the values ​​returned by the methods of web services are represented in the platform by objects of the ObjectXDTO type. Since the topic of XDTO technology is beyond the scope of this article, I will only say that for transformation this object into a list (which it is), I called its GetList() method. The rest of the code is fairly self-explanatory, including the field names of the Airport struct, which I found on the web service description page.
Now you can run the configuration and make sure that the list of the select field is populated with the names of the airports:

"Day of departure, day of arrival..."

Now I have almost everything ready to make my scoreboard function. It remains only to "paint it and throw it away" :) What will I do:

Procedure Fill in Tableau(Arrival=True) Table Tableau.Columns.Clear(); TableScoreboard.Columns.Add("FlightCode", "FlightCode"); TableScoreboard.Columns.Add(" CodeAirline", "Airline"); TableScoreboard.Columns.Add("FlightNumber", "Number"); TableScoreboard.Columns.Add(" AirportTransit", "airport transit"); TableScoreboard.Columns.Add("Airport", "Airport"+?(Arrival,"departure","arrival")); TableScoreboard.Columns.Add(" TimeSchedule", "Scheduled"); TableScoreboard.Columns.Add(" TimePlanned", "Planned"); TableScoreboard.Columns.Add(" TimeActual", "Actual"); TableScoreboard.Columns.Add("Calculated Time", "Calculated"); TableScoreboard.Columns.Add("Landing Time", ?(Arrival,"Landing","Takeoff")); TableScoreboard.Columns. Add("CombinedFlight", "Combined flight"); TableScoreboard.Columns.Add("Status", "Status"); If Not Arrival Then TableScoreboard.Columns.Add("Registration", "Registration"); TableScoreboard.Columns .Add("Landing", "Landing"); EndIf;FormElements.TableScoreboard.CreateColumns();FormElements.TableScoreboard.Columns.FlightCode.Visibility=False; If Not Arrival ThenFormElements.TableScoreboard.Columns.CalculatedTime.Visibility=False; EndIf; If Arrival Then Data=ServiceAeroflot.Arrival(SelectAirport, DateFlight).GetList("list "); Else Data=ServiceAeroflot.Departure(SelectAirport, DateFlight).GetList("list "); EndIf; TotalRecords=Data.Number( ); For ii=0 by TotalRecords-1 Loop Record=Data.Get(ies); NewRow=TableTable.Add(); NewRow.AirlineCode=Record.company; NewString.FlightNumber=Record.flight_no; NewString.AirportTransit=Record.airport_inter; NewRow.Airport=Record.airport; NewString.TimeSchedule=Record.sched; NewLine.TimePlanned=Record.plan; NewString.TimeActual=Record.fact; NewLine.CalculatedTime=Record.calc; NewString.DropDownTime=Record.real; NewRow.UnionFlight=Record.union_flight_no; NewRow.Status=Record.status; If Not Arrival Then NewString.Registration=Record.is_check; NewRow.Landing=Record.is_board; EndIf; EndCycle; EndProcedure

In order to check how it all works, I added an "Update" button with the corresponding image to the form's command bar, and wrote the following in its handler:

Procedure CommandPanel1 Refresh(Button) Fill inScoreboard(FormElements.PanelScoreboard.CurrentPage=FormElements.PanelScoreboard.Pages.Arrival); EndProcedure
Save, run, select, click, get:

Afterword

It's amazing, but after the article was written and published, it turned out that the respected ZAV had already published a similar example on IT-Land "e: http://itland.ru/biblio/detail.php?ID=1060
In order to avoid possible accusations of plagiarism, I strongly recommend that you read this article too and compare the approaches of the authors.

Print (Ctrl+P)

The Web services mechanism in 1C:Enterprise is a means of supporting Service-Oriented Architecture (SOA).
A service-oriented architecture is an application architecture in which all functions are defined as independent services with callable interfaces. Accessing these services in a certain sequence allows you to implement a particular business process.
Service-Oriented Architecture offers a new approach to building distributed information systems in which software resources are treated as services provided over a network. This approach allows you to quickly consolidate distributed components (services) into a single solution to support certain business processes.
The Web services mechanism makes it possible to use 1C:Enterprise as a set of services in complex distributed and heterogeneous systems, and also allows it to be integrated with other industrial systems using a service-oriented architecture.
The 1C:Enterprise system configuration can export its functionality via Web services. Web service definitions are defined in the configuration tree and made available to arbitrary information systems by publishing them on a web server.
In addition, 1C:Enterprise can access third-party Web services both through static links defined in the configuration tree and through dynamic links created using the 1C:Enterprise language. Rice. 1. Web Services

At the heart of the service architecture of the 1C:Enterprise 8 system is the service manager. The service manager performs the following functions:
● managing a pool of connections to infobases;
● support for WSDL description of the service;
● implementation of the SOAP protocol, message serialization, calling the corresponding service.
The service manager runs in the service host process, which performs the function of receiving/transmitting messages from/to the service manager. The service host can be an IIS or Apache web server.
The service manager contains a pool of connections through which interaction with the databases of the 1C:Enterprise system takes place.
The Web services mechanism implemented in 1C:Enterprise supports the following standards:
● SOAP 1.1,
● SOAP 1.2,
● WSDL 1.1,
● WS-I Basic Profile 1.1,
● HTTP 1.1,
● TLS 1.x (TLS 1.1 and 1.2 are supported if no client certificate needs to be passed to the server), including cryptographic algorithms,
corresponding to GOST R 34.10-2001, R 34.10-94, R 34.11-94 and 28147-89;
● MTOM;
● Authentication: Basic, NTLM/Negotiate.

To access the Web service, you must use the address, which is formed as follows:

http://host/base/ws/WebServiceName

Http://host/base/ws/WebServiceAddress.

Let's take a closer look at the components of the address:

http://host/base is a common URL used to access, for example, an infobase using a web client. If delimiters are present, specifying delimiter values ​​using the Z parameter is not supported command line launching the client application.

ws indicates that a Web service is being accessed (as opposed to hs, which defines access to an HTTP service, see here).

WebServiceName - The name of the Web service. Set in a property of the Web service object.

WebService Address - describes an alternative name for accessing the Web service. Set in the Publish File Name property of the Web service object. Can be changed when publishing the Web service.

Calls by the WebServiceName name and the WebServiceAddress address of a Web service are equivalent.

Exposing Functionality Through Web Services

To make the functionality of the 1C:Enterprise system available to external consumers of Web services, you need to do the following:
● create the required number of Web services in the configuration,
● publish Web services using a dedicated configurator tool.
The description of the procedure for publishing Web services and the description of using Reverse Proxy to access 1C:Enterprise is written in Chapter 7 “Administrator's Guide” on the ITS disk.
Creating a Web service is:
● adding the Web service configuration object to the metadata tree,
● describing the operations that the created Web service can perform,
● describing the parameters of Web service operations.
The Web service configuration object contains a module that creates procedures in the built-in language that are executed when certain Web service operations are called. Web service operation parameter types are described using XDTO types and can be either XDTO values ​​or XDTO objects.
The call to the Web service goes like this:
● a suitable connection is selected from the connection pool with information base; in the absence of a required connection, a connection is created;
● a new session is created and an event is raised for the created session SettingSessionParameters(in session module);
● the requested Web service method is called, and the handler is invoked SettingSessionParameters()(in the session module) each time an uninitialized session parameter is accessed.
ADVICE. It is not recommended to perform resource-intensive operations in an event handler SettingSessionParameters.
Event SettingSessionParameters The session module is called on the server in privileged mode. The called service module is executed on
server in normal mode.
The session module is used to initialize session parameters and execute a certain set of commands when calling any 1C:Enterprise Web service.

Sample Web Service Implementation

For example, you need to create a Web service of the 1C:Enterprise system, which should return the composition of its tabular section according to the passed invoice number. A similar example using HTTP services will be discussed in another article.
To describe the return value, let's create an XDTO package DataExpense Invoice with namespace http://www.MyCompany.ru/shipment, containing three types of XDTO objects:
● Nomenclature – for transferring data of the Nomenclature lookup element. This type of XDTO object will contain the following properties:
● Name – string type from the namespace
Full name– string type from namespace http://www.w3.org/2001/XMLSchema;
● BarCode - string type from namespace http://www.w3.org/2001/XMLSchema;
● PurchasingPrice – type int from the namespace http://www.w3.org/2001/XMLSchema.
StringInvoiceInvoice– to transfer the data of one line of the invoice. This type of XDTO object will contain the following properties:
● Nomenclature – type Nomenclature from the namespace ; is a reference to an XDTO object,
which we defined above;
● Quantity - type int from the http://www.w3.org/2001/XMLSchema namespace;
● Price – type int from the http://www.w3.org/2001/XMLSchema namespace;
● Sum is an int type from the http://www.w3.org/2001/XMLSchema namespace.
Sales Invoice– to transfer data of all lines of the invoice. This type of XDTO object will contain a single property:
● Composition - type StringInvoiceInvoice from namespace http://www.MyCompany.ru/shipment. Represents a reference to an XDTO object,
which we defined above. In order for this property to contain an unlimited set of values, you must set it
property Upper bound to -1.
After the necessary XDTO types have been created, a new Web service must be added to the configuration DataExpense Invoice with the following property values:

Namespace URI - http://www.MyCompany.ru/shipment;
● XDTO Packages - DataExpense Invoice;
Publication File Name– shipment.1cws .
The generated Web service should have a Get operation with the following property values:
return typeSales Invoice from namespace http://www.MyCompany.ru/shipment;
Possible empty value- installed;
● Procedure name - Get .
For the Get operation, define the DocumentNumber parameter with the following property values:
● Value type - type string from the namespace http://www.w3.org/2001/XMLSchema;
Transfer Direction - Input.
After that, you should open the module of the created Web service and place the Get() function in this module, which will be executed when this Web service is called.

Function Get(DocumentNumber) Export // Get the invoice object by the passed number DocumentReference = Documents.Invoice. FindByNumber(DocumentNumber, CurrentDate()); If DocumentReference.Empty() Then Return Undefined; EndIf; Document = DocumentReference.GetObject(); // Get the types of XDTO objects NomenclatureType= FactoryXDTO.Type("http://www.MyCompany.ru/shipment", "Nomenclature"); Outgoing InvoiceType = FactoryXDTO.Type("http://www.MyCompany.ru/shipment", "Invoice"); StringInvoiceInvoiceType = FactoryXDTO.Type("http://www.MyCompany.ru/shipment", "Invoice line"); // Create an invoice XDTO object Outgoing Invoice = FactoryXDTO.Create(Consignment InvoiceType); For Each LineDocument From Document.Composition Loop // Create invoice line XDTO objects // and nomenclature StringInvoiceInvoice = FactoryXDTO.Create(StringInvoiceType); Nomenclature = FactoryXDTO.Create(NomenclatureType); // Fill in item properties Nomenclature.Name = Docstring.Nomenclature.Name; Nomenclature.FullName = DocumentString.Nomenclature.FullName; Nomenclature.BarCode = DocumentString.Nomenclature.BarCode; Nomenclature.PurchasePrice = Docstring.Nomenclature.PurchasePrice; // Fill in the properties of the invoice line th Invoice line. Nomenclature = Nomenclature; Invoice Line.Quantity = Document Line.Quantity; Invoice Line.Price = Document Line.Price; Expense Invoice Line. Amount = Document Line. Amount; // Add an invoice line Invoice.Composition.Add(Invoice line); EndCycle; // Return the invoice Return Sales Invoice; EndFunctions

Working with third party web services

1C:Enterprise can use web services provided by other providers in several ways:
● using static links created in the configuration tree;
● using dynamic links created by means of the built-in language;
● a combination of the previous methods.
The advantage of using static links is more speed, because the description of the provider's web service is obtained once, when the link is created. In the future, when accessing this web service, the existing description of the web service is used.
When using dynamic links, the description of the supplier's web service will be obtained by 1C:Enterprise each time the web service is called, which will naturally slow down the work with this web service. However, the advantage of this approach is the ability to obtain an up-to-date description of the provider's web service. When using static links, to get the actual description of the web service, you should re-import the WSDL description using the configurator and save the changed configuration.
When using applied solutions, a situation may arise when the same web service is provided at different addresses (URL), but has exactly the same description (WSDL). In this case, there is a need to load the description of the web service into the configuration (create an object in the tree of configuration objects), but at the time of use specify the specific address where the web service is located. The combined method allows you to work in this way. As an example, consider the following situation: there is a replicated web service that performs
some function. An applied solution written in 1C:Enterprise uses the services of this service, while the address of the service can be different (the service is replicated), and the description is fixed. Then, a description of the web service can be loaded into the application solution, and in the settings of the application solution, provide for entering the address of a specific instance of the service, which (address) will be used during operation.
Another way is also available: a dynamic link is used, but the web service location address is not obtained from the description file (WSDL), but is directly specified when the object is created.
When trying to load a Web service description in the configurator (creating a static link) or using a dynamic link (using a WSDefinition object), the system checks the loaded Web service description (WSDL). If there is an error in the Web service description (from the "point of view" of the 1C:Enterprise system), then the description will not be loaded and an exception will be generated. The text of the exception will contain a detailed diagnosis of the reasons for the failure to download. WSDL errors are listed in the order in which they were encountered. Each WSDL error contains an entry detailing the following:

<Тип элемента с ошибкой>.<Имя>
[<Тип элемента с ошибкой>.<Имя>[…]]
<Описание ошибки>
<Тип элемента с ошибкой>
<Имя>
In this description:
● Error element type - WSDL element type. Most often corresponds to the tag name in the xml file describing the Web service.
● Error Description - Description of the specific error.
● Name - The name of the WSDL object in which the error occurred.

An example of using a static WS link

As an example of using third-party web services, consider accessing the Web service that was previously created in the example above.

First of all, you need to add a new WS-reference configuration object named InvoiceData to the configuration tree that references the published service. To do this, import the WSDL description of the published service and specify the URL as http://www.MyCompany.ru/shipment/ws/Shipment.1cws?wsdl. The description of the import of the WSDL description is written in another article.
After that, for example, in the receipt module, you can create the procedure below. It populates the tabular section of the document with the supplier's invoice data received using the supplier's web service.

Procedure GetDataInvoice(Supplier Invoice Number) Proxy = WSReferences.InvoiceData. CreateWSProxy("http://www.MyCompany.ru/shipment", "Invoice Data", "Invoice Data"); DataInvoice = Proxy.Get(); If DataInvoice = Undefined Then Return; EndIf; // Fill in the incoming invoice with the received data For Each Line Invoice From DataInvoice.Composition Loop NewString = DocumentObject.Content.Add(); NewString.Quantity = StringInc.Quantity; NewLine.Price = LineInc.Price; NewLine.Amount = LineInc.Amount; // Find the item of the nomenclature according to the passed data // (for example, by barcode) NewString.Nomenclature = Directories.Nomenclature. FindBy Props("Barcode", StringInk.Nomenclature.BarCode); EndCycle; EndProcedure

If the address of the real location of the service differs from the address that was used when loading the web service description into the configuration,
then the new address must be explicitly specified when creating the WSProxy object:

An example of using a dynamic WS link

Using a dynamic link differs from using a static link only in the way the WS proxy is created and there is no need to create a WS link in the configuration tree.
Compared to the example presented in the previous section, unlike creating a proxy based on a static link, when using a dynamic link, the WS proxy is created using the constructor as follows:

// Create a WS proxy based on the WS definition
Definition = New WSDefinitions (“http://www.MyCompany.ru/shipment/ws/Shipment.1cws?wsdl”);
Proxy = New WSProxy (Definition , “http://www.MyCompany.ru/shipment”, “Invoice Data”, “Invoice Data Soap”);
Whereas creating a WS proxy based on a static link looks like this:

// Create a WS proxy based on the link
Proxy = WSReferences.InvoiceData. Create WSProxy (“http://www.MyCompany.ru/shipment”, “Invoice Data”, “Invoice Data”);
If the address of the actual location of the service differs from the address specified in the WSDL file used to create the web service definition, the new address must be explicitly specified when creating the WSProxy object based on the web service definition:

// Create a WS proxy based on the WS definition Definition = New SDefinitions ("http://www.MyCompany.ru/shipment/ws/Shipment.1cws?wsdl"); Proxy = New WSProxy(Definition, "http://www.MyCompany.ru/shipment", "Invoice Data", "Invoice DataSoap",);

Editing Web Service Properties

On the Basic tab, enter the name, synonym, and comment of the object.
On the Operations tab, subordinate objects Operations are created, which, in turn, can have subordinate objects Parameters necessary for working with objects of this type. Description of subordinate objects is performed in the properties palette.

Properties "Operations"

In addition to the general properties of configuration objects, a Web service operation contains the following properties:

● Return Type - The type of value returned by the Web service operation. Can be an XDTO value type or an object type
XDTO.
● Can be null - Indicates whether the return value can be null.
● In Transaction - Indicates whether the Web service module code will be executed in a transaction or not. If the property is set, then when the Web service is called, a transaction will automatically be started, and when the Web service ends, the transaction will either be committed or the transaction will be rolled back (depending on the results of execution). If the property is not set, when starting the execution of the Web service module
the transaction will not start.
● Method Name - The name of the exported procedure of the Web service module that will be executed when this property is called.
The Subsystems tab indicates which subsystems the objects of this type belong to.
The following properties are defined on the Other tab:
● Namespace URI - Contains the namespace URI of the Web service. Each Web service can be uniquely identified in its own way.
name and the URI of the namespace it belongs to. The service namespace must not be the same as known namespaces that are already in use or reserved by other organizations. It is recommended that the service namespace include a fragment that is unique to the organization that develops the Web service. For example, for an organization named Promresurs, it makes sense to start all namespaces with a prefix, such as http://promresurs.com. Then the namespace URI of the Web service will look like http://promresurs.com/public/services/OurService.
● XDTO packages - a list of XDTO packages whose types can be used as operation return types and Web service operation parameter types.
● Publish File Name - The name of the Web service description file that is located on the Web server.
The Module button opens the Web service module editor.

"Parameter" properties
In addition to the general properties of configuration objects, the Web service operation parameter contains the following properties:
● Value Type - The value type of the Web service operation parameter. May be an XDTO value type or an XDTO object type.
● Can be empty - indicates whether the value of the operation parameter can take an undefined value.
● Transfer Direction - Specifies the direction of data transfer using this parameter. Possible values:
● Input - means that the parameter is used to pass data to the Web service;
● Output - means that the parameter is used to receive data from the Web service;
● Input-Output - means that the parameter can be used both for transmitting data and for receiving data from the Web service.

The topic title is really a question, because 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 is that the code below will work, however, my phrases will only be 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 then be launched on a computer located in another city or even country. All this is abbreviated as RPC (Remote Procedure Calling - remote procedure call). Examples include CORBA technologies, and for Java - RMI (Remote Method Invoking - remote method invocation). And everything seems to be good in them, especially in CORBA, because 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 network protocols instead of simple HTTP, which will crawl through any firewall. The idea of ​​a web service was to create such an RPC that would be pushed into HTTP packets. Thus began the development of the standard. What are the basic concepts of this standard:
  1. SOAP. Before calling a remote procedure, you need to describe this call in an XML file of the SOAP format. SOAP is just 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 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 were 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 file describing a web service and nothing else.
Why so short you ask? Can't you go into more detail? Probably you can, but for this you will have to turn to books such as Mashnin T. "Java Web Services". There for the first 200 pages goes detailed description each tag of the SOAP and WSDL standards. Is it worth it? In my opinion, no, because all this is created automatically in Java, and you only need to write the contents of the methods that are supposed to be remotely called. So, in Java there is such an API as JAX-RPC. If anyone does not know when they say that Java has such and such an API, this 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 buzzword these days. This is not so, because now web services have moved away from the original idea and allow not only calling remote methods, but also simply sending document messages in SOAP format. Why this is needed, I don’t know yet, it’s unlikely that the answer here will be “just in case, it’s suddenly needed.” I myself would like to learn from more experienced comrades. And finally, JAX-RS appeared for the so-called RESTful web services, but this is a topic for a separate article. This introduction can be completed, because. next we will learn how 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 the endpoint (such as the endpoint where SOAP messages from the client reach). 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 remotely call the desired web service method
You can start a web service in different ways: either describe a class with a main method and run the web service directly as a server, or deploy it on 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 web service classes here, please publish them so that everyone who contacts you can use the web service. Regardless of how the web service is launched, we will have the same client.

Server

Launch IDEA and create a new project Create New Project. Specify a name hellowebservice and press the button Next, then the button Finish. In folder src create a package en.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( // say 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 applies to the SOAPBinding class. The only difference is that SOAPBinding is an annotation with parameters. 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 our interface logic and create a HelloWebServiceImpl class in our package. By the way, I note that the class ending with Impl is a convention in Java, according to which the implementation of interfaces is so designated (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 good manners require it: package ru. javarush. ws; // same annotation as for interface description, import javax. jws. webservice; // but here it is used with the endpointInterface parameter, // indicating the full name of the interface class of our web service@WebService(endpointInterface= "en.javarush.ws.HelloWebService") public class HelloWebServiceImpl implements HelloWebService ( @Override public String getHelloString (String name) ( // just return the greeting return "Hello, " + name + "!" ; ) ) Let's run our web service as a standalone server, i.e. without the participation 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 we'll create a HelloWebServicePublisher class with the method main: package ru. javarush. endpoint; // class to start a web server with web services import javax. xml. ws. endpoint; // class of our web service import en. javarush. ws. hellowebserviceimpl; public class HelloWebServicePublisher( public static void main(String. . . args)( // start 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 run this class by clicking Shift+F10. Nothing will appear in the console, but the server is running. You can verify this by typing http://localhost:1986/wss/hello?wsdl in your browser. The opened page, on the one hand, proves that we have a web server (http://) running on port 1986 on our computer (localhost), and, on the other hand, shows the WSDL description of our web service. If you stop the application, then the description will become inaccessible, as well as the web service itself, so we will not do this, but move on to writing the client.

Client

In the project folder src let's 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 exception will occur when working with the URL object import java. net. MalformedURLException; // classes to parse xml with wsdl description // and reach for the service tag in it import javax. xml. namespace. Qname; import javax. xml. ws. service; // interface of our web service (we need more) import en. javarush. ws. hellowebservice; public class HelloWebServiceClient( public static void main(String args) throws MalformedURLException( // create a link to the 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 WSDL description tag - definitions // look at the 1st argument in the targetNamespace attribute // 2nd argument look 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 to the port tag nested in it, so that // get a reference 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("JavaRush" ) ) ; ) ) I gave a maximum of 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, JavaRush! If you didn’t see it, then you probably forgot to start the web service.

Conclusion

This thread presented brief digression to web services. Once again, much of what I wrote is my guess about how it works, and therefore I should not be trusted too much. I would be grateful if knowledgeable people correct me, because then I will learn something. UPD.

In this article, I will describe the principles of working with Terrasoft web services from external applications. Using these mechanisms, you can implement various integration tasks with any external system.

There are two ways to work with Web services from third-party applications, it all depends on the purpose of use and the specific programming language:
1. Working through Terrasoft COM-objects
2. Working with Web services directly

Working through COM objects

The first option is the least time consuming and more convenient, but it requires the Terrasoft libraries to be registered on the client machine (to use COM objects). In this case, all work with Web services will be performed by Terrasoft COM objects, providing access to data and objects through the object model of the Terrasoft platform: IDataset, ISelectQuery, etc.

To connect programmatically, you need to execute the following code (example in Jscript, but this can be implemented in any language that works with COM objects):

// Instantiate Connector and Configuration COM objects
WSConnector = new ActiveXObject( "TSDskObjectLibrary.DskConnector") ; // For versions 3.4.0+, the object is created by ActiveXObject("TSObjectLibrary.Connector")
var WSConfiguration = new ActiveXObject( "TSObjectLibrary.Configuration") ;
WSConfiguration.DBExecutorTypeCode = "WebServices" ;

// Caching the created connection
Connector.Attributes("WSConnector" ) = WSConnector;

// Setting the connection string and the name of the configuration configured on the server
WSConfiguration.SetConnectionString(
""URL=http://192.168.227.128/TSWebServicesServerLibrary.dll/soap/IServer"" +
","ConfigurationName=Dev332"" ) ;

// Open configuration
var IsConnected = WSConnector.OpenConfiguration(
wsconfiguration,
1 , // Authentication type: 0 - Windows Authentication, 1 - Server
"ddd" , // Username
"" ); // Password

After a successful connection, we can access any objects, receive data, etc. For example, obtaining data about counterparties:

// Getting the ds_Account service from the connector to web services
var AccountDataset = WSConnector.Services .GetSingleItemByUSI ("ds_Account" ) ;

// Preparing the dataset: closing and clearing the filters
AccountDataset.Close();
EnableDatasetFilters(AccountDataset, false ) ;

// Applying a filter by the ID of the current record
ApplyDatasetFilter(AccountDataset, "ID" , dlData.Dataset ("ID" ) , true ) ;

// Open dataset
AccountDataset.Open();

// Read data
if (AccountDataset.IsEOF ) (
var Value = "(no data)" ; !}
edtWSName.Value = Value;
edtWSOfficialName.Value = Value;
edtWSCode.Value = Value;
) else (
edtWSName.Value = AccountDataset.ValAsStr("Name" ) ;
edtWSOfficialName.Value = AccountDataset.ValAsStr("OfficialAccountName" ) ;
edtWSCode.Value = AccountDataset.ValAsStr("Code" ) ;
}

// Closing the dataset
AccountDataset.Close();

Attached is a complete example of working with Web services in Jscript using COM objects.

Working with Web Services Directly

This type of work is more difficult because all requests to Web services must be sent independently, and you must also process the response from the server yourself. This does not use Terrasoft COM objects, so there is no need to install and register Terrasoft libraries on each client computer from which web services will be requested.

Requests to Web services can be sent based on their interface (WSDL) - descriptions of all methods with parameters.

To simplify the development of programs for working with Web services, some IDEs, such as Visual Studio, provide a WSDL (Add WebService Reference) import, while the IDE itself generates wrapper classes for working with Web services. By calling the methods of such a class, you will simply call the corresponding methods of the web service.

The simplification is that to call a Web service method, you need to send a full XML request, and with the help of wrapper classes, you simply call the corresponding method with parameters.

Example in C# :

// Create a web service client
ws. IServer sc = new ws. ServerClient(); // ws.IServer is a wrapper class for working with Terrasoft Web services
ws. OpenConfigurationRequest rqOpenConfiguration = new ws. OpenConfigurationRequest(); // Requests to open configuration
ws. OpenConfigurationResponse rsOpenConfiguration = new ws. OpenConfigurationResponse();

// Open configuration
rqOpenConfiguration. ACompressionLevel = 0 ; //Without compression (zip)
rqOpenConfiguration. AConfigurationName = Configuration;
rqOpenConfiguration. ADBExecutorTypeCode = "MSSQL" ;
rqOpenConfiguration. AUserName = UserName;
rqOpenConfiguration. AUserPassword = Password;
rsOpenConfiguration = sc. OpenConfiguration(rqOpenConfiguration) ;

At the same time, data transfer, splitting large data into packets, parsing the server response, etc. need to be implemented by yourself.

Attached is a complete example of working with Web services in C#.

Special thanks to Alexander Kravchuk for providing examples.

Fortunately, there are no restrictions on working with web services.

Adding a Web Service to the Metadata

Open the configuration tree, branch Are common, Further Web services, add a new web service (let's call it my_ws) and fill in the properties as shown in the figure.

It is necessary to make a few clarifications about the properties of web services

  • XDTO Packages— this field specifies the list of XDTO packages whose types can be used in the value returned as a result of the web service operations.
  • Namespace URI is a string that specifies the namespace URI for this web service. Any web service can be uniquely identified by the combination of its name and namespace. It must be clearly understood that this property has nothing to do with either the physical address of the web server, or the site of the organization, etc. It's just a virtual address. Therefore, it is necessary to assign a distinct name that can tell, for example, about the area where the web service is located and used. In particular, there may be an abbreviation of the typical configuration to which the web service belongs.

Web service operations

To ensure the functioning of a web service, it is necessary to create operations for it that will perform certain actions, and, if necessary, return the necessary data.

As an example, let's create an operation for our web service that will return the classic phrase "Hello world!". Let's call her hello:

Let's create a function in the web service module Hello World(), the reference to which we will insert into the corresponding property of the operation.

HelloWorld() Function Return "Hello World!" ; EndFunctions

But this operation has one drawback. It cannot transfer raw data. For these purposes, web service operations use their subordinate objects − Options.

Let's add one more operation - HelloUsr, and create a parameter for it Name.

This operation will return a greeting to the user by calling the following function:

Function HelloUser(UserName) Return "Hello, " + UserName + "!" ; EndFunctions

Publishing a Web Service

Now we are all set to publish the web service. To do this, you need to log into the configurator with administrator rights. Click on the label 1C right click and select the appropriate menu item:

In the menu choose Administration —> Publishing to a web server

In the window that opens, enter the name of the publication, check the item Publish Web Services and also mark the web service we created:

WS links

To work with web services, such a 1C object is used as WS link. It is a WSDL description of a web service obtained by importing from the source on which the web service is located. That is, first of all, we need to know the address where we can get the WSDL description of the web service. In relation to our example, in accordance with the settings that we made in the process of creating and publishing a web service, this address will look like this

http://localhost/professia1c/ws/my_ws.1cws?wsdl

Consider what parts this address consists of.

  • http://localhost/- This address indicates the physical location of the web server. Since I have it on the local machine, then localhost, but in practice it is either the IP address of the server or its name
  • profession1c is the name of the publication. We entered it into the field Name in the dialog box when publishing the web service
  • ws- a sign that we are accessing a web service
  • my_ws.1cws- the name of the publication file that we specified in the properties when creating the web service
  • ?wsdl- a parameter that indicates that we need to get a WSDL description

After publishing a web service, in order to verify that it was published successfully, you can enter the address of its WSDL description in the browser's address bar. In this case, we should receive an XML file in the browser window with something like this:

  1. Using a dynamic ws link.
  2. Creating a static ws link.

Let's take a look at each of these methods.

Dynamic WS Links

&AtServer Procedure ConnectAtServer() WSODefinition = New WSDefinition( "http://localhost/professia1c/ws/my_ws.1cws?wsdl", "Sidorov" , "" ) ; WSProxy = New WSProxy(WSDefinition, "http://www.site/" , "my_ws" , "my_wsSoap" ) ; VSProxy. User = "Sidorov" ; VSProxy. Password = "" ; TextVS=VSProxy. HelloUsr("Vasya" ) ; Message = New MessageToUser; Message. Text = TextVS; Message. To report() ; EndProcedure

As you might guess, the result of this procedure will be the text in the message box "Hi, Vasya!"

Static WS Links

Instead of programmatically creating an object WSDefinitions we can create a WS-reference metadata object directly in the configuration tree. During the creation process, a window will be displayed asking you to specify the WSDL address of the definition to import it:

After that, we can refer directly to this WS link in the code. And the procedure for accessing the web service will take the following form:

&AtServer Procedure ConnectThroughReferenceAtServer() WSProxy = WSReference. WSlink_my_ws. CreateWSProxy("http://www.site/" , "my_ws" , "my_wsSoap" ) ; VSProxy. User = "Sidorov" ; VSProxy. Password = "" ; TextVS=VSProxy. HelloUsr("Vasya" ) ; Message = New MessageToUser; Message. Text = TextVS; Message. To report() ; EndProcedure
 
Articles By topic:
History of search engines
Hi all! Today there will be an article about the search engines of the world, which ones generally exist, when they appeared, what drives specifically in Russia, and what is on the entire globe. The article turned out to be huge, so sit down comfortably, preferably having prepared those
Ways to increase computer RAM
How do I know if my computer's memory can be upgraded? There comes a time when you begin to realize that the computer can no longer cope with its tasks, but this does not mean that you need to buy a new one, especially if your processor is only two or three years old. All h
Why does the stalker call of Pripyat fly out xray
A large number of users of Microsoft products are reporting the loss of activation of Windows 10 and the conversion of the Pro version to Home. Users are notified about an expired key, and when they try to reactivate, they get an error 0x803fa067 for Windo
css element type selector
What a selector is in css is a description of that element or group of elements that tells the browser which element to select to apply a style to it. Let's take a look at the basic CSS selectors.1) .x .topic-title ( background-color: yellow; )