Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 08, 2012 07:03 AM by Steven Cheng - MSFT
Mar 02, 2012 04:00 PM|LINK
I haven't been able to locate this in any tutorial and I'm not sure what to search for, so maybe some experienced WCF guru can point me in the right direction.
We have a centralized database. This database pulls data from other resources every hour. We have set up views to common data (clients, employees, projects, for example), and stored procs to these views. We have created an N-Layer (BLL, BOL, DAL) to access
all of the data.
Now, we're just getting into the whole WCF scene. This data is reused by a few of our web apps. So, I've set up a service contract and service for: employees, projects, clients (for example).
When I go into my test web app, I have to load a service reference for: employes, projects, clients (for example). That's 3 references.
Is there any way to group all three of these into ONE singular reference? Example: when I reference the DLL for our central database n-layer, I have exposed all objects and managers, and all methods in those managers in one shot.
We expect to have near 20+ data views, which equals 20+ service references in a couple of our apps (they use pretty much all of the data in a variety of ways).
Any directions to maybe a WCF tutorial/example that uses neither console apps or a calculator as an example, maybe something more for the enterprise, would be extremely helpful.
Thanks in advance!
Mar 05, 2012 01:52 AM|LINK
What your meaning is that there are many DataContract classes correspond to employees, projects, clients and other custom classes in your project, and there are serveral service references are used for employes, projects, clients, causing you need to add these
service references respectively on your test web app, so you want to find a approach to group all three of these into one singular reference that you need to add only one service reference. If I misunderstood your meaning, please follow up here. Based on my
understanding, you could use svcutil.exe tool to generate client proxy class and config file for every wcf service contract (.svc file), and import this generated class into your test web app, and then add the <endpoint> (mainly includes address, binding,
contract, and bindingConfiguration) node (or you can copy it or other information from the generated config file) under <client> tag in the config file which is in the test web app.
Hope this hopes
Mar 05, 2012 02:02 PM|LINK
I think that's right. Basically, if WCF follows this pattern: add a reference for every business object (Employee, Projects, Clients for example) then WCF appears to be, a) a versioning nightmare, b) high maintenance if updating the methods on the service
It sounds like it would be much simpler, faster, and easier, to just import the business layer DLL for our centralized system into each web app.
Of course, i'm "fresh meat" in the world of WCF so maybe not...that's why I'm here.
Basically, if I can import a service reference to say: CentralDatabase.svc and expose all of the business objects (employees, client, whatever) WITHIN that, then I wouldn't need 20 service references in an application.
Hope that helps. Thanks for the reply!
Mar 08, 2012 07:03 AM|LINK
Hi Hi RagMan,
If I understand correctly, now you define a ServiceContract(interface) and Service type(implement the contract) pair for each of the database table/views in your case. Then, each of these pair result to a WCF service. And your client need to "Add ServiceReference"
against each of them.
If this is the case, I think you can consider the following approaches although they will still require quite some work for maintains all the target service contracts.
1) Use a single Service which implement multiple ServiceContracts(interfaces).
So this means you still define multiple ServiceContract types, eachf of them target a certain database table/view. However, for the service implementation, you use a single class to implement all the ServiceContracts. Then, when configuration the service, you
can only define a single <service> which contains multiple endpoints(for each of the ServiceContract it has implemented). e.g.
<service name='[service type name which has implemented all ServiceContracts]' >
<endpoint contract='[serviceContract_table1]' ... />
<endpoint contract='[serviceContract_table2]' ... />
<endpoint ... />
Here are some more reference about exposing multiple endpoints with single WCF service:
#WCF: Hosting multiple WCF services as one single service
#Multiple Endpoints for a WCF Service
2) Define a class library to encapsulate all the service references
Another approach is somewhat like encapsulating all the existing ServiceReference you've generated in a single class library. You still generating individual service references for each of the target service. But create a class library project(which add
these service references) and the class library will define a single facade class to the front applications which call the services (so that front callers only deal with the facade class).