我試過對asmx(簡單的web服務)工作正常,但對於WCf我們需要做一些不同的事情。WCF + WebClient + Powershell
可以爲WCF服務工作,因爲我也得到了WCF服務的錯誤。 我剛剛在.net中創建了簡單的WCF服務並嘗試訪問。但沒有成功。
錯誤:
$Url = "http://localhost:4637/WCFService2/Service.svc"
$webclient = new-object System.Net.WebClient
$soapMessage = @"
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:GetData>
<!--Optional:-->
<tem:value>hji</tem:value>
</tem:GetData>
</soap:Body>
</soap:Envelope>
"@
$webclient.headers.Add("SOAPAction","http://localhost:4637/WCFService2/Service.svc/GetData")
$webclient.headers.Add("Content-Type", "text/xml; charset=utf-8")
$result = ([XML]$webclient.UploadString($Url, $soapMessage))#.envelope.body.GetWeatherByPlaceNameResponse.GetWeatherByPlaceNameResult
$result
如果您能向我們顯示實際的錯誤,這將是有用的。我最初的猜測是電話會失敗,因爲你的服務期望認證通話,而你的PS客戶端代碼正在進行非真實呼叫。 – 2009-11-17 06:30:54
它給了我錯誤415. – 2009-11-18 14:58:13
任何最終解決方案與完整的源代碼? – Kiquenet 2013-03-15 10:24:48