For one project, it was necessary to use 1C web services, we built a warehouse automation system, and data collection terminals are directly connected to 1C, the clients themselves are developed on .NET. The result was a very interesting structure. The obtained information about the 1C settings in the web service mode and writing a simple configuration and a client in C # in the form of a tutorial of laboratory work, which was then successfully presented at the institute.
The lab got a slightly convoluted name:
Organization of information exchange between client-server multi-platform solution using Web-Services in the example of the source developed on the 1C: Enterprise 8.2 platform and the client on the .NET 4.0 platform in C #Anyone who is interested, please under the cat.
')
Objective
To master the technology of building web services, the formation of a WSDL description of a web service. Learn the principles of serialization of objects in XML schema for the possibility of transmission via Web-Services.
Hardware and software
- Microsoft Windows 7 x64
- Platform 1C: Enterprise 8.2
- Internet Information Server
- Visual Studio 10 Ultimate
Theoretical introduction
Increasingly, there are exchanges using the technology of Web-Services. This is convenient, because for a host database, it is enough to install a Web Service extension and a data handler, and for a client's decision to connect to a Web Service. The technology is multiplatform and at the moment its use is very relevant.
Examples of web services using the WSDL description include:
- http://www.cbr.ru/scripts/Root.asp?Prtid=DWS web service of the Central Bank, for receiving daily data.
- http://api.yandex.ru/speller/doc/dg/concepts/api-overview.xml Yandex web service spell checker.
- https://www.flightstats.com/developers/bin/view/Web+Services/WSDL A number of web-based aviation statistics services, for monitoring flights, weather information, etc.
WSDL (Web Services Description Language) is an XML-based web services description and access language. (specification
http://www.w3.org/TR/wsdl ).
SOAP (Simple Object Access Protocol) is a protocol for exchanging structured messages in a distributed computing environment. SOAP is used for exchanging arbitrary XML messages and remote procedure call (RPC). (specification
http://www.w3.org/TR/soap/ ).
XDTO (XML Data Transfer Objects) is a mechanism for object data modeling described using an XML schema (for more information, see
http://v8.1c.ru/overview/xdto.htm ).
Most of the primitive type serialization methods are developed by W3 and their description is in the namespace "
http://www.w3.org/2001/XMLSchema ".
Work assignment
Task 1: Installing the 1C: Enterprise platform, installing the IIS server components, connecting the 1C Web Extensions with the IIS server.
When installing the 1C: Enterprise platform, you must install a Web Extension.

Fig. 1. Selected components at the time of installation 1C
In the menu "
Control Panel \ All Control Panel Items \ Programs and Features " You need to install additional Windows components "
Enable or disable Windows components " where you specify IIS components. In addition to the components selected by default, you need to add more components related to ISAPI technology. It is thanks to this technology that the 1C web server extension has the ability to contact the IIS web server and the βby URLβ authentication type to allow the web service using authentication 1C database users. After installation, it is recommended to restart the operating system.

Fig. 2. Selected Components at IIS Installation
In the menu "
Control Panel \ All Control Panel Items \ Administrative Tools" launch the
IIS Manager Manager console, where you open the
Application Pools item and open the
DefaultAppPool pool in the context menu select
Advanced Options ... where the
32-string applications are allowed "Must be set to"
True ". This is necessary for the Web-Extensions 1C, because it is a 32-bit application. This is convenient for debugging (because when publishing from the configurator, it will default to β
DefaultAppPool β), I recommend creating separate pools for each service without a managed environment for production.
In the same
IIS Manager Manager , select the
Default Web Site item, select the
Authentication action where you need to enable the option:
Anonymous Authentication .
Now it is possible to publish Web-Services 1C on the IIS server. But in order to be able to execute this publication, it is necessary to run the 1C: Enterprise Configurator on behalf of the β
Administrator β user.
Task 2: Creating a simple 1C configuration.The first thing to start with is the development of any configuration: you must create the Administrator role (In accordance with the
methodology for developing configurations , it should be called
Full Rights )
We believe that the database contains information on all orders, containing the quantity and type of item that was ordered, in one order there may be a list containing the item and quantity, the order also has its own number and date of its creation. Information about all orders must be transmitted through the Web-Service.
To describe this, you need to create database objects:

Fig. 3. Data structure in the created 1C configuration
Reference "
Nomenclature ", without additional details. Details "default" contains information about the name and code of the item.
The document β
Customer 's
Order β, which will contain the tabular part β
Goods β, each line of which will have information about the item (element of the type β
Reference Reference.Nomenclature β) and quantity (element β
Number β of type β
Number β unsigned with 15 characters to a comma and 3 after).
Then you can run 1C in enterprise mode and create several documents filled with the nomenclatures we created and the corresponding quantity.
Task 3: Creation and publication of Web Service 1C.In the β
General β grouping configuration, create a new element of the β
XDTO-packages β type, initially for transferring the item. It can be called, for example, β
NomenclatureXDTO β. URL namespace, in accordance with the WSDL specification, you must assign the URL of the specification address of the package, for example
"
Company.com/1C/Nomenclature ". In this package, you need to create an object type, for example, β
Nomenclature β, which contains the β
Code β and β
Name β requisites, with the corresponding type β
string (http://www.w3.org/2001/XMLSchema) β.
Now you need to create a second XDTO package, which will contain information about customer orders, it can be called β
ClientOrderXDTO β in the namespace β
company.com/1C/ClientOrder β. First of all, you need to connect the import directive "
company.com/1C/Nomenclature " in order to use the item serialization package we created. This is necessary for the transfer of the nomenclature contained in the tabular part of the document "
Customer Orders ".
Now you need to create the type of the object β
ClientOrderRow β, containing one row of the table part. This type will consist of a set of details β
Nomenclature β and β
Count β, respectively, for the nomenclature, you must specify the object type βNomenclature (http://company.com/1C/Nomenclature)β, and for the quantity, β
double (http: // www.w3.org/2001/XMLSchema) β.
The type of the object that contains the order itself can be called β
ClientOrder β and must contain the order number, the creation date, and an array of elements from the table part of the order. β
Number β of type string, β
Date β of type β
dateTime (http://www.w3.org/2001/XMLSchema) β and β
Products β of type β
ClientOrderRow (http://company.com/1C/ClientOrder) β, it is necessary to specify that the minimum number is β
0 β, and the maximum number is β
-1 β, which means that this object will be an array.
But since it is necessary to return a list of orders, you need to create an object type containing this array, so you need to create another item called β
ArrayOfClientOrders β, which will have just one props called β
ClientOrder β of the type β
ClientOrder β
(http: // company .com / 1C / ClientOrder) ".

Figure 4. XDTO package structures in 1C
At this, the creation of a description of the transmitted values ββcan be considered complete. It is necessary to describe the web service itself and its methods.
In the grouping "General" configuration you need to create an object, Web-Service. It can be called "
Service ". In the βOtherβ tab, you must specify the namespace to which the web service belongs, for example, β
company.com/1C β, as well as the list of XDTO packages containing the newly created packages β
company.com/1C/Nomenclature , company.com/ 1C / ClientOrder . In the βOperationsβ tab, create a β
GetClientOrders β method that will return β
ArrayOfClientOrders (http://company.com/1C/ClientOrder) β values, while setting the ability to return null values ββand click on the field with a magnifying glass called βMethod Name β, Thereby a function will be created in the web service module, which will be called when accessing this web service method.
In order to correctly describe the function that gets from the database and returns a list of customer orders, you need to know the internal language 1C, because the code for this function is in Appendix 1. It needs clarification that β
Factory XDTO β is some manager that performs serialization objects, and this serialized object must be returned. In this case, all the orders contained in the database are sampled, the number, date, and rows of the table part are serialized, while the nomenclature needs additional serialization, and the already packed object is inserted into the general structure. An array of packed objects is assembled, serialized into an array package. And it is sent to the client as the result of the called function.
To publish a web service in the 1C Configurator menu, select β
Administration \ Publish on a web server ... β, then specify the name of the web service publication, for example, β
Company β, the service name, for example, β
Service β and the address β
service.1cws β as well as specify the path for publication, for example, "
C: \ inetpub \ wwwroot \ Company \ ".
After this, the WSDL structure of the Web Service will be available at the address β
localhost / Company / ws / service.1cws? Wsdl β
Task 4: Creating a client in C # .NET 4.0 platform.In Visual Studio, create a new C # console application.
Next, call the context menu on the β
Reference β project element, and perform the β
Add service reference ... β action, in the opened menu click on the β
Advanced ... β button, a window will open where you must click on the β
Add Web Reference ... β button.
A menu will appear in which you must paste the link to the WSDL description of the web service.

Fig. 5. Connecting a web service to a project in C #
For a web service created in 1C, this link will look like β
localhost / Company / ws / service.1cws? Wsdl β; after correctly getting the description of the web service, you must specify the name of the .NET namespace, from which the web address will be available the service, for example β
CompanyService β, then click on the β
Add Reference ... β button, Visual Studio will automatically generate classes according to this description. In the project, it will suffice to call the methods of the generated class, while serialization and calling will be performed by the .NET platform.
Next, you need to write a program that will access the web service, and output the data to the user. To do this, you need to know the C # language, the program code is presented in Appendix 2. From this code, it is necessary to clarify that the creation of the β
Service β object is nothing but the creation of a service call manager. From this name will call the web service methods.
"
_1CWebServiceClientConsole " is the common
namespace of the project, it is selected when it is created. The web service namespace obtained from the WSDL structure is fully included in the project namespace, which allows you to call remote methods βas your ownβ.
The construction of such an architecture is transparent to programmers, but it is necessary to understand at what points and what is being serialized for later transmission. Such client-server application architecture is currently the most popular.
Registration report on laboratory workReporting is not required, the creation of a working stand, and a demonstration of its work.
Job protection procedureIt is necessary to show the working stand, explain the connection order and features of the settings, as well as the features of object serialization. For successful protection you must answer all questions.
Test questions and tasks- What is the width of the web extension 1C?
- What does 1C store package structure for data serialization?
- How to get a web service description structure?
- How to connect a web service to a project being developed in Visual Studio?
- Why do I need to create a manager of complaints at the client and what is it like?
Appendix 1: GetClientOrders function code in 1C GetClientOrders() = XDTO.("http://company.com/1C/ClientOrder", "ArrayOfClientOrders"); = XDTO.("http://company.com/1C/ClientOrder", "ClientOrder"); = XDTO.("http://company.com/1C/ClientOrder", "ClientOrderRow"); = XDTO.("http://company.com/1C/Nomenclature", "Nomenclature"); = ; . = " | ., | ., | . | | . "; = .(); = .(); .() = 0 Null; ; = XDTO.(); .() = XDTO.(); .Number = .; .Date = .; ..
Appendix 2: C # program code that accesses a web service using System; using _1CWebServiceClientConsole.CompanyService; namespace _1CWebServiceClientConsole { class Program { static void Main(string[] args) { using (Service service = new Service()) { service.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12; service.Credentials = new System.Net.NetworkCredential("LOGIN", "PASS"); var arrayOfClientOrders = service.GetClientOrders(); if (arrayOfClientOrders == null) Console.WriteLine(" "); foreach (var clientOrder in arrayOfClientOrders) { Console.WriteLine(" β" + clientOrder.Number + " " + clientOrder.Date); Console.WriteLine("-----"); foreach (var clientOrderRow in clientOrder.Products) { Console.WriteLine(clientOrderRow.Nomenclature.Name + " " + clientOrderRow.Count); } Console.WriteLine("-----"); } } Console.ReadKey(); } } }