来自powershell的Wcf服务调用 [英] Wcf service call from powershell
问题描述
大家好,
我想从powershell调用WCF服务。以下是我的代码。
$ url =http://abc.com/abc.svc
try {
$ myService = New-WebServiceProxy -Uri $ url -ErrorAction Stop -NamespaceWebServiceProxy-ClassUSZip
$ myService | Get-Member -Name TestforSUMO
$ myService.definition
(这样可行,所以我可以访问WCF方法)
$ result =false
$ resultSp =false
$ myService.TestforSUMO(测试,[ ref] $ result,[ref] $ resultSp)
写$结果
}
catch [System.Net.WebException] {
写([string] :: Format(错误:{0},$ _。Exception.Message))
}
但TestforSUMO方法给出错误:请求失败,HTTP状态为400:错误请求。
我不是得到什么问题。请帮帮我。
svc.cs代码
___________________
[WebInvoke(Method =GET) ,BodyStyle = WebMessageBodyStyle.Wrapped,RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)]
public void TestforSUMO(string InputString,ref Boolean OutputString)
{
OutputString = true;
}
在WCF配置文件中_____________
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>
我尝试过:
在Webconfig文件中做了一些更改
What I have tried:
Did some changes in Webconfig file
推荐答案
url =http://abc.com/abc.svc\"
try {
url = "http://abc.com/abc.svc"
try {
myService = New-WebServiceProxy -Uri
myService = New-WebServiceProxy -Uri
url -ErrorAction Stop -NamespaceWebServiceProxy - USZip
url -ErrorAction Stop -Namespace "WebServiceProxy" -Class "USZip"
这篇关于来自powershell的Wcf服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!