简体   繁体   中英

WCF Service to talk to WCF Service

I have a solution with 3 projects

  1. Winform Client
  2. WCF Service hosted in a windows service
  3. WCF Agent hosted in a windows service

The client (Item 1) talks to the agent (Item 3) via the service (Item 2) - all using WCF. The client (item 1) gets information from an SQL database via the service (Item 2) - using WCF.

Hence here is how I designed it. Item 1 contain a WCF client to talk to Item 2 over WCF Item 2 contains a WCF service so it can service item 1 requests. It also contains a WCF client (to talk to 3) Item 3 contains a WCF service so it can service item 2 requests.

I add a service reference to item 2 in item 1's project i add a service reference to item 3 in item 2's project

is this how it should be done give that everything is in the one solution ?

Because item 2 and item 3 are self hosted in 2 windows services, every-time i recompile my code i have to stop Item 2 and item 3 services manually in Services.MSC, compile , start Item 1 and Item 2 services and finally run my Winform client by pressing play in visual studio. Is there a better easier way of doing all this?

鉴于您的WCF服务和您的代理都托管在Windows服务中并在某台计算机上运行(我想)。您只能使用一个Windows服务来执行wcf代理和wcf服务这样您只能启动和停止一个服务

Are item 2 and 3 (the Windows services) installed from their project locations (probably the bin\\debug folder)? If so, I'm guessing that you're running into an issue with the compiler not being able to write the .exe file (because it's in use, since the services are running).

In this case, I'd recommend installing the actual windows services from a different location (for example, C:\\WindowsServices\\Service1 and C:\\WindowsServices\\Service2). That way, as long as you aren't making changes to the code of either of the services, you can compile your solution (which includes item 1) while the Windows services are running, as the compiler will be writing the .exe file to the project bin\\debug folder, not the folder(s) where the services are actually running from.

This will allow you to make changes to your windows application, recompile and test.

Another alternative would be to remove (or exclude) the two windows services from the solution that you have your windows application in.

EDIT

If I understand your question, you're asking what is the proper way to reference WCF services when they are in the same solution? In that case, it sounds like you have it set up correctly (though it's a little hard to tell).

Basically, for a client to communicate with a WCF service, you need to have a reference to that service so you can generate the proxy. The proxy is what you use to actually communicate with the service.

Item 1 will have a service reference to item 2 (the WCF service).

Item 2 will have a service reference to item 3 (another WCF service).

The fact that item 2 is itself a WCF service doesn't prevent it from being a client to another, different WCF service.

As long as you're using service references for the WCF services (as opposed to regular assembly references) it sounds to me like you're set up correctly. Move the installation of the services to a different location and your issue with not being able to rebuild the solution should go away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM