Setting WCF endpoint address at runtime?

If I have the following:

WSHttpBinding binding = new WSHttpBinding(); 
EndpointAddress endpoint = new EndpointAddress(new Uri("http://xxx:pppp/MyService")); 

MyServiceClient client = new MyServiceClient(binding, endpoint); 

      

How do I set the snap snap to the endpoint? If it helps my app.config to set:

<endpoint address="http://xxx:pppp/Design_Time_Addresses/WcfServiceLibrary/ManagementService/"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IManagementService"
          contract="ServiceReference.IManagementService">
        <identity>
              <dns value="localhost" />
        </identity>
</endpoint>

      

However, I want the user to configure this before starting the client.

thanks

+2


a source to share


2 answers


A very simple fix! Sorry to ask a stupid question!



binding = new WSHttpBinding("WSHttpBinding_IManagementService");

      

+3


a source


To configure the binding administratively, you need to add a binding section to your app.config file:

<system.serviceModel>

  {...}

  <bindings>
    <wsHttpBinding>
        <binding name="WSHttpBinding_IManagementService" {other parameters ...} />
    </wsHttpBinding>
  </bindings>

  {...}

</system.serviceModel>

      



And if you don't feel comfortable with manual editing, you can use the WCF Service Configuration Editor, which you can find in Visual Studio's Tools> WCF Service Configuration Editor.

0


a source







All Articles