1

If I want to remove necessity of app.config configuration from my Client side code and initialize client from my c#. Defining Bindings and EndPoint in my C# code. What would be a c# version of following client side code:

<client>
            <endpoint address="http://employeetstsvc/Employee.svc" binding="wsHttpBinding"
                bindingConfiguration="StandardEndpoint" contract="ServiceReference2.IHREmployee"
                name="StandardEndpoint" />
        </client>

Any ideas?

Lost
  • 12,007
  • 32
  • 121
  • 193

1 Answers1

1

Something like below. See more Here

String baseAddress = "http://employeetstsvc/Employee.svc";

WSHttpBinding binding1 = new WSHttpBinding();

using(ServiceHost host = new ServiceHost(typeof(Employee)))
{
   host.AddServiceEndpoint(typeof(ServiceReference2.IHREmployee),binding1, baseAddress);
}
Rahul
  • 76,197
  • 13
  • 71
  • 125
  • This is actually client side configuration. Seems like the answer you sugegste is server side. I am sorry I should had been more specific. I updated my question so that there is no more confusion – Lost Sep 23 '15 at 21:04
  • @CoffeeBean, didn't you say that *initialize client from my c# defining Bindings and EndPoint in my C# code*? Bit confused now... – Rahul Sep 23 '15 at 21:06
  • I am sorry for the confusion. I am just coding the client. `"http://employeetstsvc/Employee.svc"` already exists. and I want to call that service but I want to skip the app.config configuration and initialize the proxy from the C# code – Lost Sep 23 '15 at 21:12
  • @CoffeeBean, Uhh!!! You mean, don't want to create the proxy using service reference and directly from code? – Rahul Sep 23 '15 at 21:13
  • @CoffeeBean, What you are looking for is here http://stackoverflow.com/questions/8361646/create-wcf-client-without-auto-generated-proxy – Rahul Sep 23 '15 at 21:16
  • Well to backtrack a little bit. When I added the service reference in my client side code, it created Proxy class in 'reference.cs'. However though, it did not add any configurations in my app.config. So I am trying to invoke the client from my C# code and define in code rather than depending on config file. – Lost Sep 23 '15 at 21:16