none
Service configuration at client side

    질문

  • 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]

    2012년 3월 12일 월요일 오후 3:39

답변

  • 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.

    • 답변으로 제안됨 Dragan Radovac 2012년 3월 15일 목요일 오전 8:46
    • 답변으로 표시됨 Yi-Lun Luo 2012년 3월 16일 금요일 오전 9:26
    • 답변으로 표시 취소됨 Sukumar Raju 2012년 3월 22일 목요일 오전 9:45
    • 답변으로 표시됨 Sukumar Raju 2012년 3월 22일 목요일 오후 2:08
    2012년 3월 14일 수요일 오전 1:16
  • 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]

    • 답변으로 표시됨 Sukumar Raju 2012년 3월 22일 목요일 오후 2:08
    2012년 3월 22일 목요일 오후 2:08

모든 응답

  • Hello, 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.

    2012년 3월 13일 화요일 오전 2:10
  • 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.

    2012년 3월 13일 화요일 오후 4:40
  • 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.

    • 답변으로 제안됨 Dragan Radovac 2012년 3월 15일 목요일 오전 8:46
    • 답변으로 표시됨 Yi-Lun Luo 2012년 3월 16일 금요일 오전 9:26
    • 답변으로 표시 취소됨 Sukumar Raju 2012년 3월 22일 목요일 오전 9:45
    • 답변으로 표시됨 Sukumar Raju 2012년 3월 22일 목요일 오후 2:08
    2012년 3월 14일 수요일 오전 1:16
  • 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]

    • 답변으로 표시됨 Sukumar Raju 2012년 3월 22일 목요일 오후 2:08
    2012년 3월 22일 목요일 오후 2:08