Good day, dear habraklyudi!
Some of you probably know that on the
1C: Enterprise 8 platform (
1C: Enterprise 8 ) some
crazy craftsmen, in addition to applications for accountants, make, for example, games. But this is not about game development, although to some extent, web services can be used for this.
Although the
1C: Enterprise 8 platform is substantively oriented, but due to the presence of
COM ,
OLE ,
XML ,
HTML ,
SOAP and some other technologies, it can also be used for tasks not directly related to business automation. Personally, I am attracted to it by a very fast development speed, debugging and deployment of the application. These characteristics for me are key when choosing a platform for prototyping.
')
Under the cut, I'll use a simple example to show how quickly you can implement a web service on the
1C: Enterprise 8 platform, 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 was decided to be implemented on
1C . The project is still under development, but I am increasingly inclined to make the final implementation on this platform.
Setting an example problem
For example, we will develop a small web service that provides remote file storage. Of the functions of a web service, we implement only the placement of a file on a server and its receipt. To access the web service, we will use HTTP authentication.
Especially for Cyrillic haters, the entire code (and the name of the platform) is presented in English writing.
So let's get started.
Database Development
I hope to add a new application for development on the
1C platform will not cause anyone any difficulties. In general, when adding (
1 ) it is necessary to indicate its name and location. To directly develop an application, go to
Designer mode (
2 ).

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

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

Everything, the database structure for file storage is implemented. We will store only the binary data of the file itself, the name is not needed for our example. If you still need it, it is also solved quite simply - we add another requisite to store 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 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 write several lines of code for them:
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
All the functions we need to receive and place the file on the server are implemented. It remains only to get users for HTTP authentication and publish our web service.
Publish to web server
At the beginning of development, there are no users in the application and access to the information database is allowed without entering a name and password. In order to fix this you need to add users to the information database. These users will also be used for HTTP authentication. The first thing we do is add a role with full rights.

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


After that we will add normal users to the list.

After adding users 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. We just need to press the
Publish button.

This is all published by the web service can already be used.
It seems to me that reading this text will take much longer than the implementation took. I hope the respected habra people were interested to learn that prototyping web services on the
1C: Enterprise 8 platform is quite fast and easy. In some development environments, the usual “Hello world” is much more difficult to implement.