1

I am in the process of converting our win forms application to use a WCF service instead of client calls to a SQL database.

Im not sure whats best practice but we have identical database schemas on about 600 databases.

i was hoping to find a solution here where i in the startup of the winform application declare the WCF service to use this database. as of i'm trying to avoid in every single method to pass a parameter for what connection string to use.

i have some understanding of WCF but i know very little of "public declarations" and the connection context, and have not found any good examples for my scenario.

is this even possible?

if anyone can guide me in the right direction or hand me some sample code it would be very much appreciated! :)

Thanks in advance

2 Answers 2

1

WCF does support sessions. So you could pass which database you want to use in the first call, and all other calls would use the value in session.

See: http://msdn.microsoft.com/en-us/library/ms733040.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Shiraz! I will look into this
1

WCF is a strange API, in that you'll spend the first month not getting it at all and the next several months wondering how you couldn't get it. I can answer some of your questions.

  1. The best resource I know of is the Juval Lowry book, although I hear the Bustamante book is also very good.

  2. You can spin up the WCF service in Main() before you run the Form

  3. For the design you're talking about you will probably need to have a non-default constructor for your service. This is a bit painful and I believe the Lowry book handles it. If not look at IInstanceProvider and IEndPointBehavior

That being said, I don't really see how WCF fits into this design scheme. Its really for communication between a client and server. If you're planning on using it for an SOA type design there are other methods that are a lot cleaner and more light weight. Dependency injection, etc. Can you give a more straightforward example of what you want to do perhaps? I would even suggest a class that simply wraps your database that you pass into all objects that need DB information instead of WCF.

2 Comments

Hello Steve! Thanks for your answer the main thing we want to accomplish is to lift the business-logic up to us. i am not sure what u mean by straightforward example but in the top of my head i would have some kind of "login procedure" and init the WCF/Service instance and give me access to all the methods. a typical request would be, insert, update, delete customer. Get me categories for dropdown... Search customer. im not sure how important it is but the SQL database will be on the same server as the WCF service
I still don't see how WCF easily fits into your workflow. You can make a WCF service, but its going to encapsulate all of the logic that you would put into a class that simply wraps your database. IMO you're swatting a fly with a hammer. Create a DB class that wraps all of your connection and querying logic and flow that throughout your program locally. It will be more efficient and much easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.