Call a WCF Service from client side - c#

I am going to create a WCF service(IIS host) and it will be called from client side javascript code.
When I call a WCF from client side, is the WCF a WCF library or WCF application type?
For example:
I have the javascript below.
function AddFunds() {
var postObject = {
myID: myObject.myIDNumber,
LocationID: myObject.LocationID,
fundsToAdd: CurrencyFormatted($("#txtAddFunds").val())
};
$.post('/OrServices/myService.svc/AddFunds',
JSON.stringify(postObject)
).success(AddFundsResult);
}
In the beginning, I have to create WCF Service "myService.svc", but I am not sure if it is a library or application or doesn't matter.

this answer describes the difference:
A service application includes a website host already setup for you. A service library is a library of services that a host can reference and startup.
If you start with a service library (recommended) you can then choose
any host you wish (a windows service, IIS/ASP.NET, or even a console
application) and you'd just reference your library from your new host.
Choosing a Service Application limits your host to just IIS/ASP.NET
(though this might be ok for your purposes, but will limit the
protocols you can use).
Edit: Changes in IIS since I wrote this allow for a wider variety of
protocols on ASP.NET activated services, so choosing a service
application is much less limiting than before.
if your only going to host in IIS then I would recommend to just use a Service Application. As a lot of the work is done for you.

Related

C# Calling WCF behind DMZ

I need to call a WCF service that is behind a DMZ:
WEBDMZ .. LANDMZ
------------- ------------
ClientServer => WCF service
As there is a firewall between the two it's not possible for the Client to connect to the WCF service. So I need the WCF service to connect to the client and "listen" to connections or create a tunnel somehow.
I feel it must be a very common problem but I haven't been able to find a proper solution yet. And no it's not possible to open a port. The connection have to be initiated by the WCF.
The client is a server and can easily host any MSMQ or other service.
It seems like this problem can also be referred to as "reverse proxy" or "reverse tunnel".
Solution ideas:
MSMQ hosted by Client (but I'm afraid if it would just simply be polling all the time and creating a network overhead).
A reverse tunnel/proxy?
WCF Duplex?
I'm looking for the simplest solution, preferably in C# and without 3rd party software. Perhaps there is a WCF configuration that allows for reverse calls?
With .Net version 4, you can look at WCF Routing service at here. Or you can build a routing service by yourself following example from Michele Leroux. Here is the link.
EDIT:
You can build a routing service, put it at WEBDMZ server, it will contains list of endpoint wcf service put at DMZ server. At here it will take role as a service server as well as client connect to services at DMZ server. You also can build a discovery service to configure these endpoints automatically.

WCF Service And Windows Service

I have a WCF service which serves as a remote file/folder browser. We also plan on having a Windows Service that will serve as 3 functions.
Windows Service will start the WCF service so it can do its job (part of the same project)
Windows Service will Upload some data to an SQL server every few minutes based on a timer + many other methods like this
WCF will Receive a request to run a method as requested by an asp.net client via WCF and then ask the windows service to run a method and return a result to WCF and pass back the result to ASP.net.
Item 3 is the problem. How is a windows service supposed to talk to a WCF Service (and Vice-Versa) service that both run on the same machine and are essentially the same application running as one. is it over WCF again?
Possibly i am going about this all wrong. Hopefully someone may be able to help
thanks
Damo
WCF Services may be hosted within Windows Services. See http://msdn.microsoft.com/en-us/library/ms750530.aspx. The specific example they give is for a console application, but the same concept applies.
When self hosting, you can eiter specifiy a type that will be instantiated when a client connects to the service , or you pass the instance that your clients will use when they hit the service. In either case, you can instantiate the same class or access the instance passed to ServiceHost to call methods on the service, though they would not go through the WCF pipeline. The WCF Service class can get a reference to the Windows Service class and access methods on that to allow for callbacks to occur without another trip through the WCF stack.
Alternatively, if you do not wish to self-host or your application uses WCF specific calls in the service, you can create a wcf client in the service in the same way as you would on a desktop application. Simply add a service reference as normal and use callbacks to hop back to the Windows Service code.
The first answer is correct.
I'll suggest also consider the following: if you don't have the windows service to host that wcf service, then go on with exposing new one in there. There are other options as well, but those are going lower level, so WCF is the easies and safest option. The same time - its quite elegant solution.

Two way communication using netTCPBinding

I am new to WCF (Just a day or 2). I am planning to make an application having Client/Server
WCF Service (On Server hosted as windows service):
Will invoke some commands using (Process.Start())
Will send some information from my database
Questions:
What WCF binding should I use? WsDualhttp or netTCP (Please elaborate if you can)
Does WCF works with SqlServer + EF 4.1
Server UI:
This will primarily will be used to
Start ot stop the above service
Change Address (localhost to [My Ip address]) and Port
Show status of service (Running or dead)
Questions:
How can I Change the address and port of my WCF service from this UI (it will be a different project and hence different config file).
Client App:
Used to issue commands to WCF service.
Get to know if the service is running or dead.
Receive status messages for task completion or faults.
Also, can the windows installer be combined to install ServerUI + WCF Service + Windows service?
WCF Service
Here are a couple links on choosing the right binding. Based on the scenario you're describing, I'd go with the netTCP.
C# - WCF - inter-process communication
Choosing the right WCF binding
WCF and SQL Server are independent of each other, so I wouldn't expect any problems using the Windows service to interact with your database.
I'd suggest reading up on how to start a process from a Windows service.
Server UI
I would suggest hosting another WCF service in your Windows service for interacting with your Server UI. You can use the netNamedPipeBinding since this communication channel will always be local, i.e., on the same box. So your Windows service will host two WCF services - one for the external communication with the client and one for the local communication with the configuration UI.
Installer
Yes, the Windows installer can be used, but that might be overkill for what you're describing. Of the Server UI, WCF Service, and Windows service, the only one that absolutely requires installation is the Windows service. The others could theoretically run simply by copying the assemblies to the target system. You might consider having the Windows service install itself via command line. That way you could get away with a self-extracting executable using software like WinZip. This might be less heavyweight than a formal install. If you go this route, have a look at the step-by-step here.
Ha a look at WCF duplex services:
http://msdn.microsoft.com/en-us/library/ms731064.aspx
Why do you want to have a interface to an windows service? And if you have access to IIS7 and WAS, I would recommend to use it instead of self-hosting in windows service.
Here is a good starting point for WCF Configuration Management:
http://msdn.microsoft.com/en-us/library/ff650534.aspx
Yes, you can use windows installer.
Cheers
--Jocke

Starting WCF Client in IIS

It is possible to have WCF Client that connects persistantly using duplex over net.tcp (netTcpBinding) from IIS?
i.e. the normal way would be to host it in a console app or as a windows service, my question is, could one use a shared hosting type of environment to run a WCF Client application.
i.e. the application isn't ever accessible from the outside, the application just connects to another service and consumes a remote WCF service over the internet.
If the ASP.NET app is the client, you could try loading the WCF Client into an Application or Session variable.
I've done something slightly similar with a System Timer and it worked a treat.

Simplest WCF service to be consumed by C++

I'm a complete newbie regarding network stuff, but here are two scenarios I'd like to accomplish:
I have a machine running a WCF service
Scenario 1: on the same machine, I have a C++ app that needs to get data from that service
Scenario 2: on a different machine, I have a C++ app that needs to get data from that service
The data that is exchanged will typically be around 1-10KB, but the method of transfer needs to also be able to handle bigger data exchanges (1-10MB).
What kind of configuration should I use on the WCF service to make this task as easy as possible?
If you want a service that can be accessed by non .NET code, the appropriate binding to use is basicHttpBinding. This way you will generate a service that adheres to the standard published web service protocol.
If you are writing a client in unmanaged C++, calling a web service is supported by ATL.
See http://msdn.microsoft.com/en-us/library/2k53kft2(VS.80).aspx for a walkthrough.

Categories

Resources