Menu
Is free
registration
home  /  Internet/ 1c http service. Pavel Chistov

1c http service. Pavel Chistov

Attention! Now the course is also held in the evening from 18:30 to 21:30 in an immersion format.

On the course, you will gain practical skills in using the following mechanisms of the "1C: Enterprise 8" platform:

  • WEB services (SOAP protocol)
  • JSON format
  • OData interface (automatically REST service)
  • HTTP services

IMPORTANT!!! The course is designed for programmers who have the skills to work with the XDTO mechanism, or have previously completed the course.

Description and program of the course:

The cost of the WEB-course includes:

  • 2 week course, 2 webinars with a tutor
  • certificate of 1C-Training Center No. 3 (subject to practice)

The cost of the full-time immersion course includes:

  • 2 days from 10:00 am to 5:00 pm or 4 pm from 6:30 pm to 9:30 pm
  • synopsis, headphones
  • lunches, coffee breaks
  • access for 2 years to updated videos after the end of the course
  • certificate of 1C-Training Center No. 3

Learning formats

WEB training

What is this format:The proposed format combines many of the advantages of distance learning with a face-to-face component, presented by video materials and online consultations.
The WEB-course consists of videos, practical tasks and webinars with teachers. All course materials are provided round-the-clock access via the Internet - you can study at a convenient time. The course is divided into classes. During the lesson, materials on the current topic are studied, workshops are carried out, questions are asked to the teacher. At the end of each lesson, a webinar is held, where the teacher analyzes all the questions received, typical errors, explains the correct solution. Recording of webinars is available in the portal. In this way, several sessions take place one after the other. At the end, a final independent work and the final webinar.

Duration: 2 weeks

What is this format:


Duration:16 academic hours

What is this format:The face-to-face immersion course is a format that combines all the advantages of face-to-face training, distance learning and individual training. Classes are held in an equipped classroom, you independently study the course materials (step-by-step videos) and perform workshops. At the same time, there is a teacher in the classroom who is ready at any time to answer a question and help with solving practical problems, as well as check the correctness of their implementation.
Advantages - individual consultations of the teacher on your questions, the pace of passing the material that suits you personally.
All this gives a deeper study of the course material.
It is possible to take this course from your workplace with the full effect of the teacher's presence where the student is! If you are interested in this opportunity - call us!

Duration:16 academic hours

To begin with, I once had to deal with Web services on my own. Then somehow I managed to master this business and understand what and where to press in order for everything to work. Fortunately, the configuration with which I had to work was already crammed with Web services and could be spied on and done by analogy, and on the Internet I was able to find enough articles on this case. And so, by examples (for me it is The best way study), I mastered this business, and now they no longer scare me.

SO... The main task of any integration, be it CD, Web services, or HTTP services, is to transfer something from somewhere, do something about it, and return a response. It is in this format that we will consider the new technology.

In the metadata tree, HTTP services are located in the General branch:

The new HTTP service is added just like any other metadata object. Name and synonym whatever you want. Here, only the "Root URL" is important - this, in fact, is the identifier HTTP service in this database, i.e. exactly what you write in this property, you will pass it to a third-party developer (well, or yourself) as a link to the service.

I don’t know if it is possible to write here in Cyrillic, but so that you are not laughed at in the progressive world, write in Latin).

The property Template itself is important here:

Using the template, you can later refer to the data that was passed to you. SO: all data that you want to receive from the outside can be divided into 2 blocks - mandatory and optional.

Mandatory data / parameters we push them into the template, thus if the person who accesses the service did not fill them in, then the service a priori will give an error, and you will be sure that this data is there when developing the text of the handler module. How to do it: in the Template line in curly braces "()", alternating with the "/" sign, write the names of the variables. For example, we definitely need an article - then we write / (artikul). If we need to get the SKU, name and username, the template string will look like this: / (artikul) / (name) / (user), etc. Each of these parameters in the text of the handler module can be obtained as follows: Request.ParametersURL ["<имя параметра>"]. If there are no required ones, then the template looks like this: / *.

Optional data that we want to receive through the service are NOT described in the template. When building a link, to access the service, they are described at the end of the link after the "?" Sign, separated by the ampersand "&" and have the structure<имя параметра>=<значение параметра>... In the text of the handler module, you can refer to them with the construction: Request.RequestParameters.Get ("<имя параметра>BUT: it is important to remember, since they are not required, then they may not be there, respectively, we check the value for Undefined.

Next, we add a new method for our template. The HTTP method property is important here. Them here great amount BUT we will not go into all the subtleties. To implement any of your tasks, you only need 2: GET and POST.

How to choose: If what we have described in the two previous paragraphs is enough for you to work, i.e. you can get all the data you need using the mandatory and optional parameters of the request itself, then we take GET. In this case, in any browser, if you enter the address bar correctly, you will see the result of the action of your HTTP service - PROFIT! If all of a sudden your service needs data in a more complex form (xml, for example, or something else), something that cannot be crammed into a simple address bar, then we take POST. Of the minuses, such an easy check through the address bar of the browser, as with GET, will not work, but on the Internet you can easily find some sites where you can check services by POST method(for example, the site https://www.hurl.it). In case the method is selected POST, then the request besides URL (addresses), a body appears, into which you can stuff anything you want, and in the method handler you can refer to it through the Request.GetBodyAsString () construct. Any template can have both a GET method and a POST method. They will have correspondingly different handlers, and 1C, depending on how the request was sent, will choose one or another method.

An HTTP service handler is a function that always returns a value of type HTTPServiceResponse, which is built by the constructor New HTTPServiceResponse (<КодСостояния>). <КодСостояния>- this is a number, so as not to suffer with the choice of what to write, we write: 200 - if everything is fine and you return some kind of logical value, 400 - if there is an error and you return a description of the error. This type has various methods (you can read it in the syntax assistant, everything is clearly written there). Again, you can always return everything you need as a string - the SetBodyFromString () method. (one little trick: if you return html and want the browser to display it beautifully when you enter your service address into the address bar, write in the Headers response property: Answer.Headers.Insert ("Content-Type", "text / html; charset = utf-8 ") - thereby you indicate that this is not just a set of characters, but HTML and it must be shown accordingly)

After you are done, the HTTP service needs to be published. This is done on a computer with a web server installed (I will not write about the settings, there are a lot of articles) through the menu:

Administration - Publishing on a web server.

There is a tab HTTP services. Put the jackdaws and click "Publish"

so, we got a ready-made HTTP service. HOW to contact him? If we use GET method then in address bar browser we write: http: //<имя веб сервера>/<имя базы>/ hs /<корневой URL>/<обязательный параметр1>/<обязательный параметр2> <имя не обязательного параметра 1>=<значение не обязательного параметра 1>&<имя не обязательного параметра 2> =<значение не обязательного параметра 2> .

And, finally, once again in pictures))):

In the 1C Enterprise 8.3 platform, it became possible to create HTTP services

Using the built-in language, now you can form a response to a request. With this, you have convenient access to the body, headers and line of the source request, and it is also possible to form code, body and headers the answer at your own discretion.

Compared to the web services available in the SOAP platform, HTTP services have several advantages:

  • Ease of programming the client of such services;
  • Potentially smaller amount of data transferred;
  • Potentially less computational load;
  • HTTP services are resource oriented, while SOAP services are action oriented.

The database demonstrates the implementation of http services

http service Invoice List

The http service used URL patterns, implemented property processing ParametersURL object HTTPServiceRequest
This example shows how you can create a spacer base between the production base and the corporate site.
Connection is made to the demo database " Trade Management 11", in which you need to set an additional property with the name Web password , where we will store the password for access.
The http request will be passed to the URL parameters: INN as a login and password.
When processing a request, a connection is made via ComConnector to the UT (brakes are guaranteed), and a selection is made from there
I do not claim the speed and safety of this solution, it is an example

So. A new branch has appeared in the metadata tree - HTTP services
We create new service, specify its name and root URL (list)
The root url will be used to call our http service
Next, add the URL Template to the http service, specifying "/ (Login) / (Password)"
Such a template will allow, when processing an http request, to get the corresponding structure of parameters and their values ​​in the URL parameters.
Now, add a method named "get" to our URL pattern, choose GET as the http method.
Open the handler and write the code
A method handler is a function that must return a value of type HTTPServiceReply

http service Order Status

The example implements the processing of variables passed by the POST method, the formation of a response in the form of an html page.
This time, the data is fetched from the database where the hs are located, so it works much faster than the previous http service.
When implementing working system it makes sense to create objects in the database (with the service) and configure data migration from the source database (for example, to a separate background process). When processing an http request, the selection should be made directly from the database where it is located.

Publication

There is a lot of information about installing and configuring a web server.
I used the build httpd-2.2.25-win32-x86-openssl-0.9.8y.exe from here
Installed using the "Next-Next-Finish" method :)
Publishing http services is in the same place where publishing web services was and is not particularly different.
After installing the web server in the "Configurator" mode, go to the "Administration" - "Publishing on the web server" menu
On the "HTTP services" tab, set the publication name, web server, publication directory, and mark our services (in my case, the name is "web", Apache 2.2 web server)
When publishing, the corresponding blocks are automatically written to the httpd.conf configuration file and the server is restarted (on the first publication)
Contacting the http service
Example: http: // mysite / web / hs / list, where
mysite- server address (if the web server is installed locally - you can use 127.0.0.1)
web- name specified during publication (alias)
hs- a mandatory segment of the path that informs the server that work with http services will take place
list- root url of the web service

Testing

List of invoices

http://127.0.0.1/web/hs/list/7705260681/pswMP (Do not forget to configure additional property in UT for password)

It is assumed that to access the register of documents, the user accesses a direct link containing the TIN and password

Order status

http://127.0.0.1 / web / hs / check

The request and response are located at the same URL. When entering the page, the GET method is triggered, returning an html form

When you click "Check", the order number is sent using the POST method to the same URL, the response is returned with the same request form, supplemented with data on the requested order.

In the attached file - unloading the database for 1C 8.3. The configuration includes 2 http-services (from the publication), setting up a com-connection with the UT 11 demo base, the "Order" document.

What is required for launch and testing

  • web server
  • any web browser
  • current release1C: Enterprise 8.3



Faced the need to get current state configuration. You need to get:

  • The number of documents with a certain selection;
  • The period of the last registered price for the product;
  • The number of documents posted by users in the last 10 minutes.

Considering the experience of implementing a mobile application in projects, at first the thought flashed to write a configuration for android. After weighing all the pros and cons, I came to the conclusion that to solve my problem this approach will not work. Then the course was taken to use the http service. For this, the "Statistics" http-service was registered in the configuration, the url template was added AnyURL, for which the get method was added.


After forming the objects of the configuration tree, we start writing the algorithm for generating the response. The method will return a response of type HTTPServiceResponse:

After writing the response code, we publish the http service from the configurator and access it from the browser. To access the http service, you need to address the address as in a web client by adding "/ hs / statistic /". hs tells the platform that an http service is being accessed, and statistic is the name of our service.

In my opinion, http services can be useful in case:
- Formation of statistics on configuration;
- The functionality of obtaining the status of the order by its number;
- Preparation of data for import into other systems.

Company " 1C»Actively develops the" 1C: Enterprise "platform and adds new features with each release. After the start of the development of the 8.3 branch, especially a lot of new products began to appear and due to constant employment you do not have time to test them all in action. Not so long ago I and how to develop a complete mobile app (yes, on "1C: Enterprise"), but today I would like to talk about creating HTTP services by means of the platform.

Development capability HTTP services as part of the configuration appeared in the version 8.3.5 ... During this time, the component has been updated several times, and today it is quite possible to use it without fear of the presence of "childish" errors. I have not yet had a chance to use the functionality of the 1C: Enterprise platform to create http-services in real conditions, so so far the experience is limited to educational projects. However, I see the prospects for using the mechanism of http-services in one of the current working projects. In this cycle of small notes I will try to show typical examples of use. http services in the configurations for the platform " 1C: Enterprise».

Creating the simplest http service in 1C: Enterprise 8.3

Today we will look at an example of the simplest http service, and then we will improve and complicate it. The purpose of the lesson is to understand and feel the ease of creation http services based on the 1C: Enterprise 8.3 platform.

Let's start with a problem statement. The service created within the framework of the note should be able to only two things: accept a GET request and return a response in JSON format. The task is trivial and to do something similar in PHP / ASP .NET is a matter of a few lines of code. Looking ahead, I will say that in 1C: Enterprise we need about the same (okay, you don’t have to laugh at the oddities of the 1C platform).

We will talk about the use cases of http services in a separate post, but for now, just create a new http service. For convenience, let's create a new information base with an empty configuration. Let's add one subsystem to it, which we will call “ Testing HTTP Services". Now let's open the section "General" in the configuration tree, find the group " HTTP services"And add the first web service. In the window for creating a new service, fill in the fields:

  • Name- FirstWebService;
  • Synonym- The first web service;
  • Root URL- our-services;

Pay attention to the field “ Root URL". The name specified here will be used when accessing the service. There should be no spaces here and it is advisable not to use the Cyrillic alphabet. We figured it out, then go to the tab “ Subsystems"And add the http service to the only available subsystem.

The next step is to describe the URL pattern. Let's go to the corresponding tab and add a template named “ DisplayServicesList". In the property inspector, find the property “ Sample"And write in it" / list". By doing this, we will set the path along which the interaction with the http service will take place. The template can contain Special symbols, allowing you to define the passed parameters (both required and not), but for the first example we will restrict ourselves to a simple " / list". When following this path, our only method will be triggered, and give the client a set of data.

Great, there is a template, now it's up to the method. Let's add for our template, which we'll call getServicesList... In the property inspector, we need to specify the HTTP method. The specified value determines what types of requests our method will respond to. The current task is quite possible to get by with the method “ GET”.

Our service is almost ready, all that remains is to write an event handler for the constructed method. getServicesList... You can create an event handler through the property inspector. In the body of the handler we write:

Function DeriveIndex getServicesList (Query) ArrayServices = New Array; ArrayServices.Add (New Structure ("title, description", "Service # 1", "Description of service # 1")); ArrayServices.Add (New Structure ("title, description", "Service # 2", "Description of service # 2")); ArrayServices.Add (New Structure ("title, description", "Service # 3", "Description of service # 3")); ArrayServices.Add (New Structure ("title, description", "Service No. 4", "Description of service No. 4")); JSON Record = New JSON Record; Writing JSON.SetString (); WriteJSON (WriteJSON, ArrayServices); StringForReply = JSONWrite.Close (); Reply = New HTTPServiceResponse (200); Answer.Headers.Paste ("Content-type", "application / json; charset = utf-8"); Answer.SetBodyFromString (StringForResponse, TextCode.UTF8, UsingByteOrderMark.Do not use); Refund Reply; EndFunction

Let's take a closer look at the given code. At the very beginning, I describe an array consisting of structures. We need this array purely for demonstration. We will translate all its content into JSON and give it to the client. We initialize an object of type JSON record... Be sure to call the method Set String(), because we need to get the JSON text into a string variable. Next, we call the global method Write JSON(), to which we pass an object of type JSON record and the array to be converted. Then we get the result into the variable “ StringForReply"And prepare an HTTP response.

In response, we add (see method “ SetBodyFromStrings") The resulting JSON. That's it, the demo code is ready and you can proceed to the tests.

Publishing an HTTP service in 1C: Enterprise 8.3

Let's publish the created HTTP service to test the results of the work done. For the simplest test, you must have a web server installed on your system. My role of a web service is performed by Apache... We will skip the steps required to install / configure the web server, and move on to the issue of publishing an HTTP service.

To publish, you need to go to the "Administration" menu and select " Publishing to a web server". In the window that appears, fill in:

  • Name Is the name of our solution. It will be used in the URL when accessing the published IB. For example, if you specify test here, then your IB will be available at http: // localhost / test. The test option suits me.
  • Web server- Filled in automatically. I have Apache 2.2 as my web server;
  • Catalog- path to the directory where it will be placed config file published information security;
  • Uncheck the boxes “ Publish thin client and web client», « Publish standard interface OData», « Publish WEB services by default»;
  • On the HTTP services tab, mark the flag “ Publish default HTTP services"And mark the created service in the tabular section.

Testing the HTTP service

To test the created http service, launch a browser and try to access it. If you repeated all my actions, then the path should look like this:

Http: // localhost: 9090 / services / hs / our-services / list

Pay attention to the port 9090 which is specified with a colon after the hostname. If you installed Apache with the default settings, then it will listen on port 80, therefore, you do not need to specify anything. As a result, the URL will be like this:

Http: // localhost / services / hs / our-services / list

Try to follow it, and if everything works correctly, you will get a page with data in JSON format:

[(title: "Service # 1", description: "Description of service # 1"), (title: "Service # 2", description: "Description of service # 2"), (title: "Service # 3", description: "Description of service No. 3"), (title: "Service No. 4", description: "Description of service No. 4")]

This is the end of the demo example, but I would like to finally parse the URL into its constituent elements, so that it is clear why we received just such a link.

So the first part should be clear - localhost. This is the hostname where the web server is installed. Further, there is a link (services) to the published information security. This is followed by hs, this path element indicates that we are interested in interacting with the http service. The last two elements are the root URL of our service and the URL pattern.

Instead of a conclusion

« 1C: Enterprise 8.3»Allows you to create simple HTTP services with a minimum of labor, which you should have been convinced after reading this small note. Functionality significantly expands the options for using the platform. In the following notes, we will talk about practical cases of applying the technology and consider the implementation of various solutions in practice.