C# PowerShell-无法调用传递和返回对象的web服务方法
我试图从PowerShell脚本调用web服务方法,但失败了。以下是C#代码: 这就是我在PowerShell中的称呼:C# PowerShell-无法调用传递和返回对象的web服务方法,c#,web-services,wcf,powershell,object,C#,Web Services,Wcf,Powershell,Object,我试图从PowerShell脚本调用web服务方法,但失败了。以下是C#代码: 这就是我在PowerShell中的称呼: $uri = "http://localhost/MyWcfService/MyService.svc?wsdl" $svc = New-WebServiceProxy -Uri $uri -UseDefaultCredential $t = $svc.GetType().Namespace $attributes = New-Object($t + ".MyTable")
$uri = "http://localhost/MyWcfService/MyService.svc?wsdl"
$svc = New-WebServiceProxy -Uri $uri -UseDefaultCredential
$t = $svc.GetType().Namespace
$attributes = New-Object($t + ".MyTable")
$attributes.Name = "Project X"
$attributes.Comment = "This is a test"
$resp = $svc.InsertRow($attributes)
$resp
这就是我得到的错误:
找不到“InsertRow”和参数计数的重载:“1”。第1行字符:1
+$resp=$svc.InsertRow($attributes)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo:NotSpecified:(:)[],MethodException
+FullyQualifiedErrorId:MethodCountNotFindBest
我做错了什么
更新:
这是调用$attributes.GetType()时的内置.NET类型:
我放弃了在PowerShell中调用我的RESTful Web服务。我使用了本教程,然后使用它使用C#使用服务。这一点我还没有尝试过,但我应该能够尝试(这是我的项目的要求)。看起来像是关于如何在Powershell中定义MyTable/将MyTable传递给InsertRow的问题。如果执行
$attributes.gettype()
,会得到什么?
$uri = "http://localhost/MyWcfService/MyService.svc?wsdl"
$svc = New-WebServiceProxy -Uri $uri -UseDefaultCredential
$t = $svc.GetType().Namespace
$attributes = New-Object($t + ".MyTable")
$attributes.Name = "Project X"
$attributes.Comment = "This is a test"
$resp = $svc.InsertRow($attributes)
$resp
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True MyTable Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1WcfService_MyService_s...