开发者

How do you maintain a WCF Service Library in VS2010 for both a Host and Client projects?

I have a solution in VS2010 with 3 projects:

  • WCFServiceLib - a project created with the WCF Service Library template.
  • ServiceHostConsole - a project created with Console Application template.
  • ServiceClientConsole - a project created with Console Application template.

The VS template created an app.config in the WCFServiceLib that contains all the settings for the services I want to expose.

The ServiceHostConsole has WCFServiceLib as a reference and hosts the service but does not have it's own app.config file.

If I try to run the host project without an app.config, it fails to host the services, so I moved the app.config from the WCFServiceLib to the ServiceHostConsole.

The ServiceClientConsole has a Service reference to a service inside WCFServiceLib. But once I move the app.config from the Lib project to the Host project, I can no longer Update Service Reference or add new services that I added to the lib project.

In order for the clien开发者_StackOverflow中文版t project to see the service references I have to move the app.config back to the lib project, do the updates/additions to the service references on the client, and then move the app.config back to the host project.

Note that I cannot leave a duplicate app.config file in both the Service Lib project and Host project as this will cause the host to also fail to start. This would be a bad solution anyway as it would create duplicate config in different places. A change to just one of them could create issues that are difficult to track.

It seems very strange that this moving around of the app.config file needs to happen to make things work for both the host and the client, and that they can't both work at the same time.

I'm sure this must be an issue with the way I set things up (although I set them up with the default templates), and I guess there must be a better way to solve this.

This problem becomes very annoying when you are actively developing the services and need to constantly run the host and test the client with the updated services, hence the title of the question:

How do you maintain a WCF Service Library in VS2010 for both a Host and Client projects?


WCF service library creates a config because it is used by a tool called WcfServiceHost.exe. This tool hosts your service if you try to test it without your own hosting application and based on your description it also hosted the service when you added a service reference in the client (because of that you cannot update the reference when you move the config from the library). The config in the library is never used by a hosting application and it doesn't collide with a config used by the hosting application.

A hosting application always needs its own config and there should be no problem to have a config in both the host and the library. You should not create a service reference from the library itself. Once you have your own host use it when you add service reference and maintain only the config in the host.

There is one little problem. To add service reference the service must run. If both the client and the host are part of the same solution you must run the service without debugging (or outside of visual studio) to be able to add service reference to the client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜