понедельник, 28 октября 2019 г.

Создание запроса к службе Domino Web Service с помощью XMLHttpRequest

Отправка запроса к службе domino и получение ответа

//sr - переменная с текстом зпроса, включающим метод (Hello) службы и параметр (txt=Привет из xml) метода
var sr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<" + "Hello" + " xmlns=\"" + "urn:DefaultNamespace" + "\">" +
"<txt>Привет из xml</txt>" +
"</" + "Hello" + "></soap:Body></soap:Envelope>";
//получаем объект XMLHttpRequest
var xhr = new XMLHttpRequest();

//Открывает запрос
xhr.open("POST", "http://srv30/C3257BE400246325/HelloWorldLSWSProvider?openwebservice");
//Заполняем заголовки
xhr.setRequestHeader("SOAPAction", "Hello"); //метод службы
xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); //тип содержимого запроса

//call-back функция
 xhr.onreadystatechange = function() {
   // проверяем состояние запроса и числовой код состояния HTTP ответа
   if (this.readyState == 4 && this.status == 200) {
     console.log(this.responseText);
   }
 };

//Отправка запроса
xhr.send(sr);

//Ответ возвращается в виде xml
/*
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
 <soapenv:Body>
  <ns1:HelloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:DefaultNamespace"><HelloReturn xsi:type="xsd:string">Привет из xml</HelloReturn></ns1:HelloResponse>
 </soapenv:Body>
</soapenv:Envelope>
*/


--------------------------------------------------
Web service на стороне domino:
Создается web Service Providers
Имя: HelloWorldLSWSProvider
Алиас: HWLSP
Port Type class: hwProvider
Programming Model: RPC
Soap message format: RPC/encoded
Port type name: hwProvider
Service element name: hwProviderService
Service port name: Domino

'Класс в разделе Declaration
Class hwProvider
Function Hello ( txt As String ) As String
Print "message web service"
Print txt
Hello = "Hello 111111" + txt
End Function
End Class