wcf - Call Service Fabric from .net core -


am exploring service fabric microservices functionality of azure , liking lot. have hosted simple wcf services there , can call services .net framework clients using wcfclientcommunicationfactory class. works well.

now want call microservices .net core console app. search results keywords skewed towards using .net core implement actual service, want use .net core client.

can .net core apps talk service fabric microservices yet? if so, what's .net core equivalent of wcfclientcommunicationfactory?

right name factory wcfcommunicationclientfactory, located in microsoft.servicefabric.services.communication.wcf.client namespace microsoft.servicefabric.services.wcf nuget package. it's not compatible .net core now, whole wcf approach , service fabric aren't.

service fabric microservices rest-services in end, have 3 methods host (from msdn):

  • no specific protocol: if don't have particular choice of communication framework, want , running quickly, ideal option service remoting, allows strongly-typed remote procedure calls reliable services , reliable actors. easiest , fastest way started service communication. service remoting handles resolution of service addresses, connection, retry, , error handling. available both c# , java applications.
  • http: language-agnostic communication, http provides industry-standard choice tools , http servers available in many different languages, supported service fabric. services can use http stack available, including asp.net web api c# applications. clients written in c# can leverage icommunicationclient , servicepartitionclient classes, whereas java, use communicationclient , fabricservicepartitionclient classes, service resolution, http connections, , retry loops.
  • wcf: if have existing code uses wcf communication framework, can use wcfcommunicationlistener server side , wcfcommunicationclient , servicepartitionclient classes client. available c# applications on windows based clusters. more details, see article wcf-based implementation of communication stack.

note: need asp.net core tools visual studio 2017. .net core tools visual studio 2015 no longer being updated.

note #2: while asp.net core apps can run on .net core or on full .net framework, service fabric services can run on full .net framework. means when build asp.net core service fabric service, must still target full .net framework. none of nuget packages service fabric targeted full .net framework.

asp.net core app can hosted guest executable on service fabric no code changes, recommended way hosting asp.net core in reliable service kestrel (nuget package) or weblistener (nuget package):

enter image description here

after publish server in service fabric, can connect using http protocol anywhere - web frontend, angular spa, xamarin or simple c# httpclient, client doesn't need targeted full .net framework, server is.

some sample code:

static httpclient client = new httpclient();  client.baseaddress = new uri(micro_service_uri); client.defaultrequestheaders.accept.clear(); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json"));  httpresponsemessage response = await client.getasync(path); if (response.issuccessstatuscode) {     // deserialize result json     var result = await response.content.readasasync<dtoclass>(); } 

Comments