Hi All,
I've been trawling the web but can only find detailed information on how to use powershell from C# but not the other way round.
Basically i have a web service that imports or removes a machine from SCCM collections. My code that calls it from C# is below (it is pretty simple):
ServerWebService.ServiceClient sc = new ServerWebService.ServiceClient(); errorMessage = sc.AddComputer(computerName, macAddress, collectionName, siteCode); //errorMessage = sc.RemoveComputer(computerName, collectionName, siteCode); Console.WriteLine(errorMessage);
The web service will return an error message or a success message which is then written to the console - this works fine.
However if i send the same information to the same web service using the below code:
$wbsvce = New-WebServiceProxy -Uri http://SERVERNAME/AddRemCompWebService/Service.svc?wsdl $returnMessage = $wbsvce.AddComputer($ComputerName,$MacAddress,$CollectionName,$SiteCode) Write-Output $returnMessage
I get a timeout error as seen below:
Exception call "AddComputer" with "4" argument(s): "The operation timed out" At "POWERSHELLFILELOCATION"+ $returnmessage = $websvce.AddComputer($ComputerName,$MacAddress,$CollectionName,$SiteCode)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorID : WebException
Is there anything that needs to be included in the C# web service to accept requests from powershell scripts?
I understand that this is timing out but why? I am essentially running the same code as the C# way of calling the web service?
I look forward to your replies! Thank you.