Powershell SOAP request with parameter

只谈情不闲聊 提交于 2019-12-13 04:36:37

问题


I need a powershell script to call a soap service, the problem I am currently having is the soap service method has a parameter, I know for sure that I can get the powershell script to work when the method has no parameters but as soon as their is a parameter I receive an error.

i.e.

+ $res = $req.GetResponse <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Soap request which works (powershell so I have used double quotes where appropriate):

<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>
          <CheckStockLevels/>
       </soap:Body>
</soap:Envelope>"

Soap request which doesn't work (powershell so I have used double quotes where appropriate):

<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>
          <CheckStockLevels>
             <configurationName>123</configurationName>
          </CheckStockLevels>
       </soap:Body>
    </soap:Envelope>"

Does anyone know how I should format the XML for the soap request which doesn't work?


回答1:


This works?

$soap = [xml]@'
<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>
  <CheckStockLevels>
    <configurationName>123</configurationName>
  </CheckStockLevels>
 </soap:Body>
</soap:Envelope>" 
'@


来源:https://stackoverflow.com/questions/12401776/powershell-soap-request-with-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!