none
how to refer Service URL from <applicationSettings> in web.config RRS feed

  • Question

  • HI,

    I have a class library project with WCF service references.

    When I do that I see below entries in app.config :

    <system.serviceModel>
        <bindings />
        <client />
     </system.serviceModel>
    
    <applicationSettings>
        <Test.Data.Properties.Settings>
            <setting name="Test_Data_StudentWebService" serializeAs="String">
                <value>
                     http://test.aks/StudentServices/services/StudentDataWebService
                </value>
            </setting>
        </Test.Data.Properties.Settings>
    </applicationSettings>

    I tried below:

    <system.serviceModel> <bindings> <basicHttpBinding> <!--Code omitted for clarity--> </basicHttpBinding> </bindings> <client> <endpoint address="HOW TO REFER SERVICE NAME FROM <APPLICATIONSETTINGS>"

    binding="basicHttpBinding"

    bindingConfiguration="testBinding" contract="StudentWebService"

    name="ServiceEndpoint" /> </client> </system.serviceModel>


    How can I refer to service URL and add binding information to this service ? 

    Any help is appreciated ?


    San




    • Edited by Sanjay Sutar Thursday, November 21, 2013 4:16 PM
    Thursday, November 21, 2013 4:13 PM

Answers

  • Hi,

    You can get the service url by using the following:

    string uri = Test.Data.Properties.Settings.Test_Data_StudentWebService;

    Then you can call the service by using the ChannalFactoy like below:

           BasicHttpBinding myBinding = new BasicHttpBinding();
           string uri1 = Test.Data.Properties.Settings.Test_Data_StudentWebService;
            EndpointAddress myEndpoint = new EndpointAddress(uri1);
            ChannelFactory<IMath> myChannelFactory = new ChannelFactory<IService1>(myBinding, myEndpoint);
            // Create a channel.
            IService1 wcfClient1 = myChannelFactory.CreateChannel();

    #How to use ChannalFactoy:
    http://msdn.microsoft.com/en-us/library/ms734681(v=vs.110).aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 22, 2013 6:59 AM
    Moderator