2016-07-26 60 views
0

我在soapui有一些web服務調用。我想把它們放在一個腳本中,這樣我就可以將它們作爲監視器調用。不知道什麼是最好的選擇繼續。想寫ps腳本來做這些調用,並使用腳本作爲監視器。如果您有更好的建議,請諮詢。感謝你的幫助! - 山姆如何在需要標頭Cookie的PowerShell中製作SoapUi請求?

+0

這是不真的很清楚你在問什麼,但你可以使用'Invoke-WebRequest'來調用Web請求。你應該能夠得到它與WCF一起工作(我認爲它是一個WCF服務,因爲你使用的是SoapUI)。 –

+0

你有這個工作的例子嗎?我嘗試使用此cmdlet - 沒有工作。當我從soapui發出請求時,它需要cookie的標頭。如果你能提供一個有助於遵循步驟的例子。謝謝! –

回答

0

好了,你可以發送SOAP請求是這樣的:

$soap = @" 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <Geocode xmlns="http://dev.virtualearth.net/webservices/v1/geocode/contracts"> 
     <request xmlns:a="http://dev.virtualearth.net/webservices/v1/geocode" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
      <Credentials xmlns="http://dev.virtualearth.net/webservices/v1/common"> 
       <ApplicationId>ThisIsMySecret</ApplicationId> 
       <Token i:nil="true" /> 
      </Credentials> 
      <Culture xmlns="http://dev.virtualearth.net/webservices/v1/common" i:nil="true" /> 
      <ExecutionOptions xmlns="http://dev.virtualearth.net/webservices/v1/common" i:nil="true" /> 
      <UserProfile xmlns="http://dev.virtualearth.net/webservices/v1/common" i:nil="true" /> 
      <a:Address xmlns:b="http://dev.virtualearth.net/webservices/v1/common"> 
       <b:AddressLine>1747 Reynolds St NW</b:AddressLine> 
       <b:AdminDistrict>TN</b:AdminDistrict> 
       <b:CountryRegion i:nil="true" /> 
       <b:District i:nil="true" /> 
       <b:FormattedAddress i:nil="true" /> 
       <b:Locality>Knoxville</b:Locality> 
       <b:PostalCode>37921</b:PostalCode> 
       <b:PostalTown i:nil="true" /> 
      </a:Address> 
      <a:Options i:nil="true" /> 
      <a:Query i:nil="true" /> 
     </request> 
     </Geocode> 
    </s:Body> 
</s:Envelope> 
"@ 

$headers = @{ 
    'Content-Type' = 'text/xml; charset=utf-8'; 
    'SOAPAction' = 'http://dev.virtualearth.net/webservices/v1/geocode/contracts/IGeocodeService/Geocode' 
} 

Invoke-WebRequest ` 
    -Uri http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc ` 
    -Body $soap ` 
    -Method Post ` 
    -Headers $headers 

如果您需要添加一個cookie,你可以將字符串只需添加到$headers

$headers = @{ 
    'Content-Type' = 'text/xml; charset=utf-8'; 
    'SOAPAction' = 'http://dev.virtualearth.net/webservices/v1/geocode/contracts/IGeocodeService/Geocode'; 
    'Cookie' = 'YouCookieGoesHere' 
} 
+0

謝謝!我嘗試這樣做,收到此錯誤:+調用-WebRequest的' + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [調用-的WebRequest],ArgumentException的 + FullyQualifiedErrorId信息:System.ArgumentException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand –

+0

什麼版本的PowerShell您使用的是? –

+0

的PowerShell 3.0版 –