Service configuration at client side
-
12 Mart 2012 Pazartesi 15:39
Hi there,
WCF service is referenced with in Class Library project [Add Service Reference]. Class library project uses methods from WCF Service. Class library assembly is used with in client application. So that service call can be made through class library project [Assembly].
It is mandatory to have <System.SerivceModel> section with in client application to interact with WCF service. Its not required to have service related configuration with in Class library configuration i.e., App.Config.
Query:
when number of clients consuming the same service through Class library, it is mandatory to have service related configuration with in each client's web.config file. Here service related configuration is duplicated at each client [Web.config].
Is there any solution to remove above duplication? so that clients can just have reference to Class library and consume WCF Service methods without having service related configuration at each client's Web.config ?
Help is apprecaited.
Apriori algorithm [association rule]
Tüm Yanıtlar
-
12 Mart 2012 Pazartesi 21:29
This thread may answer you question:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/5dcb15dd-8620-4268-a84e-93133d1d7fc8
-
13 Mart 2012 Salı 02:10ModeratörHello, if you want to use config, then you have to put the client side config in client application's web.config (or in case of exe, put it in the exe's app.config). Config files of class libraries will be ignored at runtime. You can also hard code everything in your client library, if you're sure the service address/binding will never change. The generated client proxy contains an overload of constructor which accepts a binding and an endpoint address as parameters. So you can just hard code them.
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email. -
13 Mart 2012 Salı 16:40
You can also hard code everything in your client library, if you're sure the service address/binding will never change. The generated client proxy contains an overload of constructor which accepts a binding and an endpoint address as parameters. So you can just hard code them.
Thanks Lante.
Do you mean to say client library as Class library project?
Constructor in class library? Can you elaborate with piece of source? bit clearly please.
-
14 Mart 2012 Çarşamba 01:16Moderatör
Yes, I mean class library. In the generated client proxy, you will find a constructor that takes a binding and an endpoint address as parameters. For example:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress(http://someaddress);
YourClient client = new YourClient(binding, address);
If you take this approach, no config file is needed, as all information is provided in code. Of course this means even the service address must be hard coded.
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.- Yanıt Olarak Öneren Dragan Radovac 15 Mart 2012 Perşembe 08:46
- Yanıt Olarak İşaretleyen Yi-Lun LuoModerator 16 Mart 2012 Cuma 09:26
- Yanıt İşaretini Geri Alan Sukumar Raju 22 Mart 2012 Perşembe 09:45
- Yanıt Olarak İşaretleyen Sukumar Raju 22 Mart 2012 Perşembe 14:08
-
22 Mart 2012 Perşembe 14:08
Yes, I mean class library. In the generated client proxy, you will find a constructor that takes a binding and an endpoint address as parameters. For example:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress(http://someaddress);
YourClient client = new YourClient(binding, address);
If you take this approach, no config file is needed, as all information is provided in code. Of course this means even the service address must be hard coded.
Thanks Yi.
Yes, Class library contains service proxy contains Binding and End Point address as you suggested (copied below).
//Binding that service can use to configure and expose endpoints BasicHttpBinding binding = new BasicHttpBinding(); //unique network address that a client uses to communicate with a service endpoint EndpointAddress epa = new EndpointAddress("http://ws-myService.svc"); //Create an instance of service client class by passing binding and end Point address ServiceContractClient client = new ServiceContractClient(binding, epa);
There is no configuration at client side . When the service reference is added to Class library it has updated App.config with service configuration, when the service configuration is hard coded through code as above configuration in App.config is NOT required.
Conclusion:- When multiple clients using a Class Library, which is consuming WCF service it is NOT required to have service configuration at each client side. Service configuration can be hard coded i.e., Binding and End Point with in Class library to consume service methods with in Class Libray.
Once again thank you for all your help here.
Apriori algorithm [association rule]
- Yanıt Olarak İşaretleyen Sukumar Raju 22 Mart 2012 Perşembe 14:08