Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,
I would like to call WCF service from powershell. Given below is my code.

$url = "http://abc.com/abc.svc"
try {
$myService = New-WebServiceProxy -Uri $url -ErrorAction Stop -Namespace "WebServiceProxy" -Class "USZip"
$myService | Get-Member -Name TestforSUMO
$myService.definition
(This works fine so I am able access WCF methods)

$result = "false"
$resultSp = "false"

$myService.TestforSUMO("Test",[ref]$result, [ref] $resultSp)
Write $result
}
catch [System.Net.WebException]{
Write ([string]::Format("Error : {0}", $_.Exception.Message))
}


But TestforSUMO method gives Error: The request failed with HTTP status 400: Bad Request.

I am not getting what is a problem. Please help me.

Code of svc.cs
___________________
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public void TestforSUMO(string InputString, ref Boolean OutputString)
{
OutputString = true;
}

In WCF config file _____________
<behaviors>
      <endpointBehaviors>
        <behavior name="CommercientclientAPI.Service1Behavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>


What I have tried:

Did some changes in Webconfig file
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900