开发者

WCF + WebClient + Powershell

开发者 https://www.devze.com 2022-12-11 20:54 出处:网络
I tried it works fine for the asmx (simple web services) but for WCf do we need to do some thing different.

I tried it works fine for the asmx (simple web services) but for WCf do we need to do some thing different.

Can the Same work for the WCF services as i get the error for the WCF service also. i just created the Simple WCF service in .net and tried to access. but was not successful.

Error:

$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")

$resul开发者_运维技巧t = ([XML]$webclient.UploadString($Url, $soapMessage))#.envelope.body.GetWeatherByPlaceNameResponse.GetWeatherByPlaceNameResult

$result


Do you really want to manually fill in the SOAP packet and send it? If not, then do a Get-Help on New-WebServiceProxy assuming you are running PowerShell 2.0. This cmdlet will create a proxy object that you can directly program against.

0

精彩评论

暂无评论...
验证码 换一张
取 消