0

I would like to create a windows form application,

But I would like this widows form should host WCF server so other application will be able to communicate with this windows application.

So I add to the windows application project interface for the WCF contract and add also class that implement this interface.

Now on the windows form application constructor I add

ServiceHost calcHost = new ServiceHost(typeof(Service));
calcHost.Open();

and now I need to implement that the WCF methods will be able to interact with the windows form.

I was unable to do that.

My question is – is my architecture is correct or should I need to create the WCF differently if it ok, how should the WCF will interact with the windows form application?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MoShe
  • 6,197
  • 17
  • 51
  • 77
  • 1
    Typically, a Windows application can be started and stopped at any time by the user. A WCF service should be available (again typically...) at all times. So architecturally these should be two separate components. The Windows application should be as light as possible, making calls to the WCF service. – Richard Ev May 02 '12 at 12:09
  • I know but in this case it is ok for me – MoShe May 02 '12 at 12:10
  • The winforms will have another functionalities, or only the WCF service? – Vinicius Ottoni May 02 '12 at 12:10
  • yes this is the issue I need that from the wcf service I will be able to interact will the windows form such as change text box text etc – MoShe May 02 '12 at 12:15

2 Answers2

2

Here is an example for you which contains the code: WCF Application Manager example

Linger
  • 14,942
  • 23
  • 52
  • 79
bresleveloper
  • 5,940
  • 3
  • 33
  • 47
1

if you want calls to the wcf service to change the windows form then I think you need to pass a reference to your form into your WCF service and then have your service methods call methods on your form when they get called.

I think you will need to create your own service host implementation so you can pass a reference to the form to the service instances that the host creates (or host your service as a singleton). See this question for more details.

Community
  • 1
  • 1
Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • 1
    would you be able to explain me how should I do it? how should I add referance ? in the constructor? why I should use `ServiceHost calcHost = new ServiceHost(typeof(Service)); calcHost.Open();` – MoShe May 02 '12 at 12:23