0
votes

I'm trying to call a web service method from my PowerShell script but it's failing. Here is the C# code:

public MyTable InsertRow(MyTable data)
{
   var dataContext = new MyEntities();

   dataContext.MyTables.AddObject(data);
   dataContext.SaveChanges();

   return data;
}

This is how I call it in PowerShell:

$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

And this is the error that I get:

Cannot find an overload for "InsertRow" and the argument count: "1". At line:1 char:1 + $resp = $svc.InsertRow($attributes) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest

What am I doing wrong?

Update: This is the built-in .NET type when I call $attributes.GetType():

IsPublic IsSerial Name                                     BaseType                                                                                                      
-------- -------- ----                                     --------                                                                                                      
True     True     MyTable                            Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1WcfService_MyService_s...
1
Looks like an issue with how MyTable is defined/passed to InsertRow in Powershell. What do you get if you do $attributes.gettype() ?Micky Balladelli

1 Answers

0
votes

I gave up on trying to call my RESTful Web service in PowerShell. I used this tutorial to create entity data in a data service and then used this sample code to consume the service using C#. This I have not yet tried, but I should be able to use the C# code in PowerShell script (this being my project's requirement).