Invoke a ServiceFabric Service via Powershell - service-fabric-stateless

My team has developed a ServiceFabric application with several services. These services use each-other within the application, but for administration purposes, I want to call directly into one of the services from PowerShell.
From within the services a proxy object is created and used:
var myServiceProxy = ServiceProxyFactory.CreateServiceProxy<IMyServiceInterface>("fabric://Application/MyService")
var result = await myServiceProxy.SendSomeData(bytearrayHere);
I want to be able to send a file to the same service via PowerShell. Is this possible and how do I do that? This is on my box so I have all the certificates/secrets that may be needed.

You should be able to create the ServiceProxy by using PowerShell New-Object and directly call SendSomeData.
As a workaround, you could create a service that hosts a web api, and POST a file to it by using the PowerShell Invoke-RestMethod.

Related

How to not expose REST calls to the client in Oracle Visual Builder?

After working with Oracle ADF for a while, I am now developing an application using Oracle Visual Builder. When calling REST services using the action chain component "Call REST", the call is visible in the browser console. (The services are added from the catalog, they are not defined by their specific endpoints)
Using Firefox's Inspection tools I can right click the request, edit it and resend it successfully despite the service using authorization.
In Oracle ADF I would simply call the service in a managed bean, the user wouldn't know I called it.
How can we not let the client/user know we called the service that in Visual Builder (or hide it from the console)?
Is there a way to call REST services other than the "Call REST" component in the Action Chain tools?
That's a key difference between the architecture of ADF that was running logic on the server, and VB that runs the logic on the client side.
Any web page that calls a REST endpoint (including from JS code) will show the REST call in the browser's log - this is not a VB specific behavior.
The security should be defined on the REST side requiring proper authentication to invoke the REST endpoint.
Maybe consider making the call from a custom JS function - and calling the JS function from the action chain?

Defining Web Service via VB.NET Code

Good Day Everyone -
I'm using VB.NET within VS2013 (Professional) and have a question about defining a Web Service binding via code.
I can successfully had a Service Reference via Solution Explorer and connect to a specified URL for the web service I'm trying to access.
What I am looking for is some direction on how to define the endpoint via code; the web service I'm hitting will be local to each facility and I need to allow a user to define the endpoint URL on the fly.
Any thoughts or insight would be appreciated.
After researching I found the problem.
When I connected to the Web Service VS stored the connection details in app.config in the folder of the project. At run time, VS compiled the app.config into .config which had to go with compiled application.
Once I did this I was able to connect without a problem to the defined WS outside of VS. Once basic connection details were present, I could successfully override the remote endpoint with whatever the user inputted.

How can I automate / schedule a WCF service call hosted in IIS?

I've got an extraordinarily simple service contract for a service that manages its own data import, similar to this:
using System.ServiceModel;
namespace Company.Services.Domain.Contract
{
[ServiceContract(Name = "ImportService", Namespace = "http://services.company.org/")]
public interface IImportService
{
[OperationContract]
ImportResponse ImportData();
}
}
I'd like to set up a scheduled task or something similar to execute this call on a daily basis. I know that I could write a console application and create a proxy via svcutil. But is there a way to configure this in IIS natively (maybe an IIS extension)? Or could I achieve something simple and elegant with PowerShell?
Just wondering what my options are.
You can have an IIS-hosted application that uses IIS auto-start, assuming you are running at least version 7.5 of IIS. The auto-start does not run on a timer, but will help guarantee that your application is always running. After IIS starts the application, your code can start a timer to call the WCF service each day.
The timer would, of course, be implemented in code. Examples of simple timer implementations include this, this, and this.
If you are using ASP.NET then put the timer start code in the Application_Start method in the global.asax file of the auto-started application.
You could use cURL (Windows and 'nix versions available): http://curl.haxx.se/
Set your scheduled task to invoke curl.exe with parameters appropriate to make a request to your web service's URL:
curl -o importResponse.txt http://services.company.org/ImportService.svc/ImportData
The -o will drop the response into a text file of the given name. Other configuration options can be found in the manual: http://curl.haxx.se/docs/manual.html
EDIT: This assumes that you're exposing a web service and GET (rather than POST or SOAP). If you're exposing a SOAP service it should still be fairly trivial because you're not passing any parameters.
curl --request POST --header 'Content-type: text/xml' --output importResponse.txt --data <SOAP/> http://services.company.org/ImportService.svc/ImportData
Alternatively, as you're using WCF you can expose your service as both a SOAP service and a RESTful web service simultaneously, by adding some configuration to your app's web.config: a webHttpBinding, a service endpoint, and an endpointBehavior, as per: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx
Check ou New-WebServiceProxy. It's very useful, you point it at the url and it loads the web ervice. You can pipe it to Get-Member to see whats available as well.
Matt
EDIT: example now I'm not on my phone :-)
# url for the service
$url = "http://services.company.org/ImportService"
# Create the service - using default credentials
$service = New-WebServiceProxy $Url -UseDefaultCredentials
# explore the service
$service | gm
for more information check out the PowerShell help
help New-WebServiceProxy

WCF - Dynamically calling different web service endpoints implementing the same interface

I have a number of different applications that implement the same contract. In my main app, I would like to have one proxy. Then dynamically, given a Uri for a particular application, I would create a web service request and call that. How can that be accomplished? Thanks!
Do these steps:
generate your client-side proxy based on one service
this will generate the C#/VB.NET classes for you, as well as the app.config (or web.config if your client is a web app)
when calling the default service endpoint, you can do something like:
YourServiceClient client = new YourServiceClient();
client.CallSomeMethod();
This will use all the settings from the default service endpoint as defined in your config file
if you need to provide a different endpoint, do this:
YourServiceClient client =
new YourServiceClient("default", "http://server/YourOtherService.svc");
client.CallSomeMethod();
There is an overload for the client constructor which will take two parameters: the name of the endpoint configuration in your client config file (you need to look that up after you've added the service reference), and the endpoint URL you want to connect to (which can be different from what's stored in the config).
If all the other parameters like service contract, binding information etc. stay the same, this method should work and it should allow you to connect to any number of varying endpoints using this second constructor overload.
When you instantiate the service client, you can set the uri
ReconcileSvc.ReconcileClient client = new ReconcileClient();
client.Endpoint.Address = new System.ServiceModel.EndpointAddress(uri);
Hope it helps.

How to create Endpoints from app.config file in WCF?

I have a service which has one endpoint , I have defined this endpoint in app.config file.
I want to know how can I create endpoints if I have app.config in program.
Please give me an idea.
Do you have a generated proxy for your service? If so, just use the proxy client!
MyServiceClient proxy = new MyServiceClient();
Optionally, you can pass in a name for the configuration to use:
MyServiceClient proxy = new MyServiceClient("MyConfigName");
No need to do anything fancy.
If you haven't created a proxy (using "Add Service Reference" in Visual Studio or svcutil.exe on the command line), you'll need to add a reference to your assembly containing the service and data contracts, and then use
ChannelFactory<IMyService> factory = new ChannelFactory<IMyService>();
IMyService proxy = factory.CreateChannel( );
Again, for creating the channel factory, you can pass in a name of a configuration section, if you have multiple, to specify which one to use.
Also, to clarify - a client can only ever have one endpoint at any given time. The service might have multiple - but the client needs to make up its mind and connect to exactly one of those - you cannot have multiple endpoints in a client (as the title of your questions appears to imply).
Marc
If you are using Visual Studio use the WCF Service Configuration Editor (found under tools). Use this to open your config file or hosted service and then you can create your endpoints there. Any new endpoint configuration info will be saved into your app.config/web.config as appropriate