我试过对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