NOTE: This page has been translated automatically from Russian to English. Original page.
1C8 + SOAP
Three ways to work with the web services of 1C.
Message from 1S8 to the web service can be done in different ways.
The first thing to understand is that 1C sends requests (actually XML) files and receives responses (usually as XML, but not necessarily because vebprogrammista program responds as she pleases).
Working with the web service, it is necessary to access the documentation, written vebrazrabotchik, because without it will not work to prepare an adequate request (XML). Examples of such queries can require the developer without any ulterior motives (the answer would be something like this ). With the hands example, it is already possible to try (feel):
strZapros is
<? xml version = "1.0" encoding = "UTF-8" standalone = "no"? >
<SOAP-ENV: Envelope xmlns: SOAPSDK1 = "http://www.w3.org/2001/XMLSchema"
xmlns: SOAPSDK2 = "http://www.w3.org/2001/XMLSchema-instance"
xmlns: SOAPSDK3 = "http://schemas.xmlsoap.org/soap/encoding/"
xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV: Body>
<GetAirportsList xmlns = "http://webservices.belavia.by/">
<Language xmlns: SOAPSDK4 = "http://webservices.belavia.by/"> RU </ Language>
</ GetAirportsList>
</ SOAP-ENV: Body>
</ SOAP-ENV: Envelope>
(c XML text had to tinker, because the pieces do not appear in the type </ SOAP-ENV: Envelope> . spaces are not needed)
oXMLHTTP = Новый COMОбъект("MSXML2.XMLHTTP");
стрURL="http://86.57.245.235/TimeTable/Service.asmx?op=GetAirportsList";
oXMLHTTP.open("POST", стрURL, 0);
oXMLHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXMLHTTP.setRequestHeader("SOAPAction", "http://webservices.belavia.by/GetAirportsList");
oXMLHTTP.send(strЗапрос);
Если oXMLHTTP.Status=200 тогда
xmlВыборкаAirport = oXMLHTTP.responseXML.SelectNodes("//Airport");
Для чКК=1 По xmlВыборкаAirport.Length Цикл
xmlВеткаAirport = xmlВыборкаAirport.item(чКК-1);
спВыбора.Добавить(xmlВеткаAirport.getAttribute("IATA"),"["+xmlВеткаAirport.getAttribute("IATA")+"] "+ xmlВеткаAirport.getAttribute("Name"))
КонецЦикла;
КонецЕсли;
It is not difficult to notice, to access the service using MSXML2.XMLHTTP object. And absolutely no mention of the mechanisms sepetsialnyh. This method is flexible.
However, an independent inquiry compilation (XML-file) are extremely lazy, and wants to simplify the process as it is. To do this you will need a service description (for example, a ). This description requires us to some understanding, the result will be the following snippet:
SOAPN = Новый COMОбъект("MSSoap.SoapClient30");
SOAPN.MSSOAPInit("http://86.57.245.235/TimeTable/Service.asmx?WSDL","OnlineTimeTable", "OnlineTimeTableSoap");
comSafeArray=SOAPN.GetAirportsList("RU");
Для чК=comSafeArray.GetLowerBound(0) по comSafeArray.GetUpperBound(0) Цикл
элемент=comSafeArray.GetValue(чК);
Если элемент.Length=2 тогда
спВыбора.Добавить(элемент.item(0).value,"["+элемент.item(0).value+"] "+ элемент.item(1).value);
ИначеЕсли элемент.Length=1 тогда
спВыбора.Добавить(элемент.item(0).value,"["+элемент.item(0).value+"] ");
КонецЕсли;
КонецЦикла;
This time the object is used MSSoap.SoapClient30. And as we know, it is quite crude (or, at least, I do not know how to cook it). Complicated and confused XML string turned into a challenge comSafeArray = SOAPN. GetAirportsList ( "RU").
However, 1C has gone to meet his faithful "friends" and has done different objects. On 1S8.2 code looks like this:
WSОпределение = Новый WSОпределения("http://86.57.245.235/TimeTable/Service.asmx?WSDL");
Service = Новый WSПрокси(WSОпределение, "http://webservices.belavia.by/", "OnlineTimeTable", "OnlineTimeTableSoap" ); cписокXDTO=Service.GetAirportsList("RU").ПолучитьСписок("Airport");
ВсегоАэропортов=cписокXDTO.Количество();
Для чК=0 по ВсегоАэропортов-1 Цикл
обАэропорт=cписокXDTO.Получить(чК);
спВыбора.Добавить(обАэропорт.IATA,"["+обАэропорт.IATA+"] "+ обАэропорт.name);
КонецЦикла;
It is possible to put even in the configuration description of the service and then the first two lines can be replaced by:
Service=WSСсылки.WSСсылка1.СоздатьWSПрокси("http://webservices.belavia.by/", "OnlineTimeTable", "OnlineTimeTableSoap" );
So do not cheat and do not grimacing you can work with web services.