Ошибка PowerShell имеет полный SOAP-ответ, а не содержимое - PullRequest
2 голосов
/ 10 июля 2019

Я звоню в SOAP API. PowerShell выдает ошибку, а ошибка содержит ожидаемый ответ! В то время как в содержимом переменной, на которую я отправляю ответ, отсутствуют некоторые данные.

[xml]$response = Invoke-WebRequest -Uri $UserURI -Method POST -ContentType "test/xml;charset=utf-8" -Body $input

$SOAPResponse = [xml]$response.Content

PowerShell возвращается:

Invoke-WebRequest : <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="https://test.safetylearning.co.uk/api/1.3/UserManagement">
<SOAP-ENV:Body><ns1:AddUserResponse><AddUserResult><errorcode>500</errorcode>
<description>Error</description><errors><item><id>52001</id><description>Unable
to add one or more users.</description></item><item><id>52010</id>
<description>User with ID ['9991'] fails</description></item><item><id>0</id>
<description>A user identified by ID ['9991'] exists</description></item>
</errors></AddUserResult></ns1:AddUserResponse>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
At C:\Temp\Delme3.ps1:37 char:18
+ ... $response = Invoke-WebRequest -Uri $UserURI -Method POST -ContentType ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Итак, я вижу нужную ошибку, т. Е. Существует пользователь с идентификатором ['9991']. Тем не менее

$SOAPResponse.Envelope.Body.AddUserResponse.AddUserResult.errors

ничего не возвращает!

$SOAPResponse.Envelope.Body.FirstChild.InnerXml

возвращается:

<AddUserResult><errorcode>200</errorcode><description>OK</description><errors /></AddUserResult>

<errors> пусто!

SOAPUI выдает правильную ошибку:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://test.safetylearning.co.uk/api/1.3/UserManagement">
   <SOAP-ENV:Body>
      <ns1:AddUserResponse>
         <AddUserResult>
            <errorcode>500</errorcode>
            <description>Error</description>
            <errors>
               <item>
                  <id>52001</id>
                  <description>Unable to add one or more users.</description>
               </item>
               <item>
                  <id>52010</id>
                  <description>User with ID ['9999'] fails</description>
               </item>
               <item>
                  <id>0</id>
                  <description>A user identified by ID ['9999'] exists</description>
               </item>
            </errors>
         </AddUserResult>
      </ns1:AddUserResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
...