WCF, how to self-host callback? - c#

I have a WCF service lib which run by a self-host [Winform] and a client [Winform], and im using NetTcpBinding.
i want the client to call a method from WCF service to Pop up a MessageBox on Self-host Winform.
the point: i want to send an image to the server side, and it should appears in a new form, but i can't communicate between WCF service library and its Self-Host Form.
please can you help with an example that shows me how would i show a messageBox on Self-host winform when a client call a method from WCF service lib.

You could create your service as a singleton and pass in the Form in its constructor. Then pass this service object into the ServiceBase.
Then when you get a function call you will have reference to the Form and can manipulate it in that fashion. Be aware of threading restriction on working with Form applications.

You can return a success or failure message from the service call which sends the image to the server side. Assuming that you were successful in sending the message to server, you can open a new form and populate the message box or whatever user interface control you wish o display to the user. As I mentioned in the comment, the service colud be multitenanted and you should not mix user interface relatd code in service layer.

Related

How to route Button events from a WPF application to a wcf service

I have a wcf service hosted in a wpf application. I also have a multiple remote clients which are communicating with the service without any problems.
I want to know how to get hold of the service instance from WPF application.
I'm trying to use the IClientCallback returned from OperationContext.Current.GetCallbackChannel<IClientCallback>()
to make a call to the operations on the client side when a button is pressed in the WPF application.
The InstanceContextMode = InstanceContextMode.Single on the service side if this helps. Please show me through a code example as I'm new to WCF.
I figured it out by myself. I had to use the one of the overloaded constructors of servicehost and pass in the class holding the data contracts.
public ServiceHost(
object singletonInstance,
params Uri[] baseAddresses

Interacting with windows service to send and receive data?

I have created a service on Windows it is installed on localhost and now have to interact with this service .
Inside my web application I'll give a query command that will be sent to this service and this service will make this query on another IP and return the result to the application .
Within the OnStart method I created a StreamWriter 's fulfilling a text file , to make sure that the service is working.
How do I send requests for this service and receive his answers ?
To solve my problem I created a socket server on this basis .
https://msdn.microsoft.com/en-us/library/bew39x2a%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/fx6588te%28v=vs.110%29.aspx
Creating the service within the same Web page solution that will display the information sought by the service.

How to control application via webservice

I want to control application (in my case it is corelDraw) ,I know I should use it's application object and I do this, but the issue now is I want to do this in webservice,
so as far as I understand if I put this code which control the application in the web-service ,my code will try to control the corel application which is on the server not on the client :(
so any hint/advice how could I do this, and control the application on the client not server ?!!!
As you already noticed web service runs on server and only result is passed to client.
Well you have a few options to control client machine over web service... Here is one of possible scenarios.
1. create web service that will provide commands for client
2. create windows service (client) that will consume your web service commands
3. inside windows service then just execute those commands in appropriate manner
Well I have to say this is not the prefered way I would take to automate corelDraw, but if you insist on using webservice as command provider it will do the job.
You need to ask yourself what is the difference between client and a server. Can a client be a server? Can a server be a client?
You make your client with CorelDraw installed to accept web-service request, i.e. effectively make it a web-service server, and then carry on as normal.
Although I would say web-service is not the best way to control such complex application as CorelDraw. I'd look in some other ways of communication between peers, like lower level network communication that would not have overhead of HTTP.

Communication Between WCF Rest Service and host application

I have a WCF Rest web service that I am hosting in a managed application. What I would like is for client input to the service to be passed to the host application for processing, and the results are then passed back to the client. From similar questions like here and here I know I can use events to pass the data from the service to my host application. However, I cannot seem to figure out how to get the resulting data passed back to the client. Is there a way to do this using the webOperationContext or perhaps by creating another event in the host application to pass the data back to the web service?

calling a WCF service object method in another WCF service

I using two WCF services. WCF service A is hosted in my .NET Winform application and WCF Service B is hosted on a Windows Service.
I am able to instantiate a client for WCF Service B and use the methods - i.e. call the WCF service hosted on Windows service from the .NET Winform app.
I am not able to accomplish the reverse with WCF Service A - i.e. call the WCF Service hosted on the .NET Winform application from the Windows Service. The call to the method times out.
I have used the WCF Test client from the Visual Studio command prompt and it can successfully make calls to WCF Service A.
Is this due to a security issue or something from the Windows Service?
Please advise.
Thanks in advance!
Subbu
I think the only viable approach (without the extreme of having some messaging infrastructure), is to have the service invoke operations back on your client via a WCF callback. A good example of this can be found here:
What steps do I need to take to use WCF Callbacks?
This is good for dealing with events that happen server side and allowing the client to respond to them. If events isn't what you're looking for, then your client could just register with the server (specifying the callback contract), and then the server can invoke your client at will.

Categories