【发布时间】:2015-12-10 23:11:45
【问题描述】:
我在 PowerShell 中发出这样的 SOAP 请求:
$uri = "https://secure.echosign.com/services/EchoSignDocumentService20?WSDL"
$sun = Invoke-WebRequest $uri -Method post -ContentType "text/xml" -InFile .\getUrl.xml
“文件”如下所示:
<api:getDocumentUrls>
<api:apiKey>redacted</api:apiKey>
<api:documentKey>REDACTED</api:documentKey>
<api:options>
<dto1:attachSupportingDocuments>true</dto1:attachSupportingDocuments>
<dto1:combine>true</dto1:combine>
<dto1:auditReport>true</dto1:auditReport>
</api:options>
</api:getDocumentUrls>
我没有收到任何错误,并且在 SoapUI 中测试的响应的 xml 如下所示:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:getDocumentUrlsResponse xmlns:ns1="http://api.echosign">
<ns1:getDocumentUrlsResult>
<errorCode xmlns="http://dto14.api.echosign">OK</errorCode>
<errorMessage xsi:nil="true" xmlns="http://dto14.api.echosign"/>
<success xmlns="http://dto14.api.echosign">true</success>
<supportingDocumentUrls xsi:nil="true" xmlns="http://dto14.api.echosign"/>
<urls xmlns="http://dto14.api.echosign">
<DocumentUrl>
<name>test.pdf</name>
<url>https://smuszconsulting.echosign.com/document/cp/2AAABLblqZhAOjW1Dv6ig0pMc1PaF5BSHiCNNVAU6PEBmVizdpa9kFwkX5wQurgfu7P0atiSKop4*/document.pdf</url>
</DocumentUrl>
</urls>
</ns1:getDocumentUrlsResult>
</ns1:getDocumentUrlsResponse>
</soap:Body>
</soap:Envelope>
我需要将该 URL DocumentUrl.url 放入一个变量中,以便将其写入数据库,但我不知道如何。
我试过了:
$newObj = $sun.getDocumentUrlsresponse.ChildNodes | % { $_.Name; $_.InnerText }
但这不起作用。该对象甚至没有被创建。
好的..我将代码更改为如下所示:
$uri = "https://secure.echosign.com/services/EchoSignDocumentService20?wsdl"
[xml]$sun = Invoke-WebRequest $uri -Method post -ContentType "text/xml" -InFile .\getUrl.xml
$nsm = New-Object Xml.XmlNamespaceManager($sun.NameTable)
$nsm.AddNamespace('ns', 'http://dto14.api.echosign')
$url = $sun.SelectSingleNode('//ns:DocumentUrl/ns:url').innerText
现在我收到此错误:
Exception calling "SelectSingleNode" with "1" argument(s): "Namespace Manager
or XsltContext needed. This query has a prefix, variable, or user-defined
function."
At C:\Program Files\DCESS_InfoGatherer\testingGetUrl.ps1:53 char:1
+ $url = $sun.SelectSingleNode('//ns:DocumentUrl/ns:url').innerText
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
有没有办法像使用 SoapUI 一样查看响应中的 XML?
我什至不知道我得到的回复是否正确。
【问题讨论】:
-
我的错。由于某种原因,我在实例化命名空间管理器后未能实际使用它。
$nsm必须作为第二个参数传递给SelectSingleNode()。请参阅我的更新答案。
标签: xml web-services powershell soap