powershell->;带有附加头的SOAP请求

powershell->;带有附加头的SOAP请求,soap,powershell-3.0,Soap,Powershell 3.0,嗨,我需要一个正确的soap请求帮助。我尝试了几种方法,但没有成功 需要生成此类soap请求: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><Action xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:env="http://www.w3.org/2003/05/soap

嗨,我需要一个正确的soap请求帮助。我尝试了几种方法,但没有成功

需要生成此类soap请求:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><Action xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:env="http://www.w3.org/2003/05/soap-envelope" env:mustUnderstand="true"/><MessageID xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">uuid:..............</MessageID><ReplyTo xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing"><Address>http://www.w3.org/2004/08/addressing/anonymous</Address></ReplyTo><To xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:env="http://www.w3.org/2003/05/soap-envelope" env:mustUnderstand="true">host_url</To><wsse:Security xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" env:mustUnderstand="true"><wsse:UsernameToken><wsse:Username xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">$login</wsse:Username><wsse:Password xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" wsse:Type="http://docs.oas
is-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">$password</wsse:Password></wsse:UsernameToken></wsse:Security></soap:Header>
<soap:Body>
      ................
   </soap:Body>
</soap:Envelope>
uuid:。。。。。。。。。。。。。。http://www.w3.org/2004/08/addressing/anonymoushost_url$login$密码
................
我无意中发现了这个获取iis内部错误500:

(...)
write-host "Sending SOAP Request To Server: $URL" 
        $soapWebRequest = [System.Net.WebRequest]::Create($URL) 
        $soapWebRequest.Headers.Add("SOAPAction","`"MethodName`"")
        $soapWebRequest.ContentType = "application/soap+xml;charset=`"utf-8`";action=`"host/MethodName`""

        $soapWebRequest.Method      = "POST" 

        write-host "Initiating Send." 
        $requestStream = $soapWebRequest.GetRequestStream() 
        $SOAPRequest.Save($requestStream) 
        $requestStream.Close() 

        write-host "Send Complete, Waiting For Response." 
        $resp = $soapWebRequest.GetResponse() 
        $responseStream = $resp.GetResponseStream() 
        $soapReader = [System.IO.StreamReader]($responseStream) 
        $ReturnXml = [Xml] $soapReader.ReadToEnd() 
        $responseStream.Close() 
        write-host "Response Received."
        return $ReturnXml 

}

$url = 'host.asmx'
$soap = [xml]@"
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:flow="host">
   <soap:Header/>
   <soap:Body>
      .....
   </soap:Body>
</soap:Envelope>
"@
$ret = Execute-SOAPRequest $soap $url; $ret | Export-Clixml  "test-$(Get-date -f yyyy-MM-dd-mm-ss).xml"; 
(…)
写入主机“向服务器发送SOAP请求:$URL”
$soapWebRequest=[System.Net.WebRequest]::创建($URL)
$soapWebRequest.Headers.Add(“SOAPAction”和“`MethodName`”)
$soapWebRequest.ContentType=“应用程序/soap+xml;字符集=`utf-8`”;操作=`host/MethodName`”
$soapWebRequest.Method=“POST”
写入主机“启动发送”
$requestStream=$soapWebRequest.GetRequestStream()
$SOAPRequest.Save($requestStream)
$requestStream.Close()
写入主机“发送完成,等待响应”
$resp=$soapWebRequest.GetResponse()
$responseStream=$resp.GetResponseStream()
$soapReader=[System.IO.StreamReader]($responseStream)
$ReturnXml=[Xml]$soapReader.ReadToEnd()
$responseStream.Close()
写入主机“收到响应”
return$ReturnXml
}
$url='host.asmx'
$soap=[xml]@”
.....
"@
$ret=执行SOAPRequest$soap$url$ret | Export Clixml“test-$(Get date-f yyyy-MM-dd-MM ss).xml”;

你的标题看起来很奇怪,把你实际上不需要的转义引号混在一起了

试着替换

 $soapWebRequest.Headers.Add("SOAPAction","`"MethodName`"")

以及

 $soapWebRequest.ContentType = "application/soap+xml;charset=`"utf-8`";action=`"host/MethodName`""

 $soapWebRequest.ContentType = "application/soap+xml;charset=`"utf-8`";action=`"host/MethodName`""
$soapWebRequest.ContentType = "application/soap+xml; charset=utf-8";