Last active
August 24, 2022 14:59
-
-
Save aleksp99/5879860cf7f9a65e989fdb36edfbb6f9 to your computer and use it in GitHub Desktop.
#PowerShell #1С #1C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clear-Host | |
# ПАРАМЕТРЫ | |
# Адрес информационной базы | |
$urlDB = "iA11/demo" | |
# Имя пользователя | |
$user = "" | |
# Пароль пользователя | |
$password = "" | |
# Имя Web-сервиса | |
$nameWebService = "WebSrv" | |
# Имя файла публикации веб-сервиса | |
$url = "WebSrv.1cws" | |
# URI пространства имен | |
$uri = "localWeb" | |
# Метод Web-сервиса | |
$method = "Sum" | |
# параметры метода (если есть) | |
$param = @{ | |
Value1 = 8 | |
Value2 = 5 | |
} | |
#Тайм-аут в секундах | |
$timeout = 10 | |
# РЕАЛИЗАЦИЯ | |
$body = "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:WName=""$($uri)""> | |
<soapenv:Body> | |
<WName:$($method)> | |
$($param.GetEnumerator().ForEach({"<WName:$($_.Name)>$($_.Value)</WName:$($_.Name)>"})) | |
</WName:$($method)> | |
</soapenv:Body> | |
</soapenv:Envelope>" | |
# Определение веб-сервисов | |
$request = [System.Net.WebRequest]::Create("http://$($urlDB)/ws/$($url)") | |
#$request.Credentials = New-Object System.Net.NetworkCredential($user, $password) | |
$request.Method = "POST" | |
$request.ContentType = "text/xml;charset=UTF-8" | |
$request.ContentLength = $body.Length | |
$request.Headers.Add("SOAPAction", "$($uri)#$($nameWebService):$($method)") | |
$request.Headers.Add("Authorization", "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($user + ":" + $password))) | |
$request.Timeout = $timeout*1000 | |
# Запись тело(метод и параметры метода) | |
$str = [System.IO.StreamWriter]($request.GetRequestStream()) | |
$str.Write($body) | |
$str.Close() | |
# выполнение метода и чтение ответа | |
$response = $request.GetResponse() | |
$reader = [System.IO.StreamReader]($response.GetResponseStream()) | |
$res = $reader.ReadToEnd() | |
$response.Close() | |
# ответ SOAP сервиса в виде XML | |
$res | Out-File D:\tmp.xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment