
Rapid prototyping of a web service on the 1C: Enterprise 8 platform
Good day, dear habralum!
Some of you probably know that on the platform 1C: Enterprise 8 ( 1C: Enterprise 8 ) somecrazy craftsmen, in addition to applications for accountants, make games, for example. But we will not talk about game development, although to some extent web services can be used for this.
Although the 1C: Enterprise 8 platform is subject-oriented, but thanks to the presence of COM , OLE , XML , HTML , SOAP technologies in itand some others, can be used for tasks not directly related to business automation. Personally, I am attracted to it by the very fast speed of development, debugging and deployment of the application. These characteristics are key to me when choosing a platform for prototyping.
Under the cut, I will show with a simple example how fast it is on the 1C: Enterprise 8 platform that you can implement a web service, develop a database for it and publish it on a web server. The above example, in a slightly modified form, is used in a large and real project, the prototype of which it was decided to implement on 1C . The project is still under development, but I am more and more inclined to make the final implementation on this platform.
For example, we’ll develop a small web service that provides remote file storage. Of the functions of the web service, we only implement placing the file on the server and receiving it. To access the web service we will use HTTP authentication.
Especially for the haters of the Cyrillic alphabet, all the code (and the name of the platform) is presented in English.
So let's get started.
I hope to add a new application for development on the 1C platform that will not cause anyone any difficulties. In general, when adding ( 1 ), it is necessary to indicate its name and location. For direct application development, you must switch to Designer mode ( 2 ).

We need only a couple of clicks to create a file vault in the database. To do this, add the FileStorage catalog (directory) to the application .

We define for it one single attribute of ValueStorage with the type of Value Storage .

That's it, the database structure for storing files is implemented. We will store only the binary data of the file itself, we do not need to store the name for our example. If you still need it, then this is also solved quite simply - we add one more attribute for storing the file name.
Now let's start developing the web service itself.
Add a new web service to the application. Give it the name FileStorageService .

Be sure to define a namespace for it.

And we add two methods PutFile ( File type base64binary) return value of type string and GetFile ( Id type string) return value of type base64binary. In the web service module, we will write a few lines of code for them: Everything that we need to receive and place the file on the server is implemented. It remains only to get users for HTTP authentication and publish our web service.
At the beginning of development, there are no users in the application and access to the information base is allowed without entering a name and password. In order to fix this, you need to add users to the infobase. Also, these users will be used for HTTP authentication. The first thing we will do is add a role with full rights.

Next, we assign this role to the first user created (Administration -> Users -> Add) - the administrator.


After that, we add ordinary users to the list.

After adding users, we will publish our web service. Publishing (Administration -> Publishing on web-server ...) is possible on IIS or Apache. The platform performs all the necessary actions for this automatically. We only need to click the Publish button .

That's all, you can already use the published web service.
It seems to me that reading this text will take much longer than the implementation took. I hope dear habra-people it was interesting to learn that prototyping web services on the 1C: Enterprise 8 platform is quick and easy. In some development environments, the usual “Hello world” is much more difficult to implement.
Some of you probably know that on the platform 1C: Enterprise 8 ( 1C: Enterprise 8 ) some
Although the 1C: Enterprise 8 platform is subject-oriented, but thanks to the presence of COM , OLE , XML , HTML , SOAP technologies in itand some others, can be used for tasks not directly related to business automation. Personally, I am attracted to it by the very fast speed of development, debugging and deployment of the application. These characteristics are key to me when choosing a platform for prototyping.
Under the cut, I will show with a simple example how fast it is on the 1C: Enterprise 8 platform that you can implement a web service, develop a database for it and publish it on a web server. The above example, in a slightly modified form, is used in a large and real project, the prototype of which it was decided to implement on 1C . The project is still under development, but I am more and more inclined to make the final implementation on this platform.
Problem statement of an example
For example, we’ll develop a small web service that provides remote file storage. Of the functions of the web service, we only implement placing the file on the server and receiving it. To access the web service we will use HTTP authentication.
Especially for the haters of the Cyrillic alphabet, all the code (and the name of the platform) is presented in English.
So let's get started.
Database Development
I hope to add a new application for development on the 1C platform that will not cause anyone any difficulties. In general, when adding ( 1 ), it is necessary to indicate its name and location. For direct application development, you must switch to Designer mode ( 2 ).

We need only a couple of clicks to create a file vault in the database. To do this, add the FileStorage catalog (directory) to the application .

We define for it one single attribute of ValueStorage with the type of Value Storage .

That's it, the database structure for storing files is implemented. We will store only the binary data of the file itself, we do not need to store the name for our example. If you still need it, then this is also solved quite simply - we add one more attribute for storing the file name.
Web service implementation
Now let's start developing the web service itself.
Add a new web service to the application. Give it the name FileStorageService .

Be sure to define a namespace for it.

And we add two methods PutFile ( File type base64binary) return value of type string and GetFile ( Id type string) return value of type base64binary. In the web service module, we will write a few lines of code for them: Everything that we need to receive and place the file on the server is implemented. It remains only to get users for HTTP authentication and publish our web service.
Function PutFile(File)
If File.Size() = 0 Then
Raise "INVALID_BINARY_DATA";
EndIf;
// Добавление файла в БД.
NewFile = Catalogs.FileStorage.CreateItem();
NewFile.ValueStorage = New ValueStorage(File);
NewFile.Write();
Return NewFile.Code;
EndFunction
Function GetFile(Id)
// Поиск файла в БД по переданному коду.
File = Catalogs.FileStorage.FindByCode(Number(Id));
If NOT ValueIsFilled(File) Then
Raise "INVALID_FILE_CODE";
EndIf;
Return File.ValueStorage.Get();
EndFunction
Web Publishing
At the beginning of development, there are no users in the application and access to the information base is allowed without entering a name and password. In order to fix this, you need to add users to the infobase. Also, these users will be used for HTTP authentication. The first thing we will do is add a role with full rights.

Next, we assign this role to the first user created (Administration -> Users -> Add) - the administrator.


After that, we add ordinary users to the list.

After adding users, we will publish our web service. Publishing (Administration -> Publishing on web-server ...) is possible on IIS or Apache. The platform performs all the necessary actions for this automatically. We only need to click the Publish button .

That's all, you can already use the published web service.
It seems to me that reading this text will take much longer than the implementation took. I hope dear habra-people it was interesting to learn that prototyping web services on the 1C: Enterprise 8 platform is quick and easy. In some development environments, the usual “Hello world” is much more difficult to implement.