tags:

views:

536

answers:

1

Hi there,

To do the above using the config file I would do:

    <endpoint
      address="...."
      binding="netTcpBinding"
      bindingConfiguration="MyBinding"
      contract="IService1">
      <identity>
        <servicePrincipalName value="name"/>
      </identity>
    </endpoint>

But how do I add it to the below code?

            Uri uri = new Uri("......");
            ServiceHost host = new ServiceHost(typeof(Service1), uri);

            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
            host.AddServiceEndpoint(typeof(IService1), binding, uri);
            host.Open();
+2  A: 

It's a bit cumbersome, you need to use the return value of the AddServiceEndpoint method and set it there:

ServiceEndpoint serviceEndpoint = host.AddServiceEndpoint(typeof(IService1), binding, uri);
EndpointAddress myEndpointAddress = new EndpointAddress(uri, EndpointIdentity.CreateSpnIdentity("YourIdentity"));
serviceEndpoint.Address = myEndpointAddress;
Marc Wittke