WCF routing with WCF service using Negotiate authentication

I have an existing WCF service that uses Transport security with Negotiate authentication with windows credentials.
The client uses impersonation with credentials accepted by the remote service. Now I want to put a WCF router in the middle.

The problem I’m facing is how to get the router to pass the client credentials the service.
Well, if I configure the router custom binding with AuthenticationSchemes.Negotiate, it will fail authentication because the router is unfamiliar with the client credentials. Then switched to AuthenticationSchemes.Anonymous and now the client can connect with the router, but the problem is there are no credentials that the router use in the channel to impersonate the client with the service (in fact this is a binding configuration error: The contract operation ‘ProcessRequest’ requires Windows identity for automatic impersonation. A Windows identity that represents the caller is not provided by binding (‘CustomBinding’,’http://tempuri.org/’) for contract (‘IRequestReplyRouter’,’http://schemas.microsoft.com/netfx/2009/05/routing’

I see in other posts that the credentials are hardcoded in the binding, not possible in my case due to security.
Logically, below is what I need to do, but how can I pass the credentials in the context
client –> (anonymous) ——> router –> (impersonate with creds) –> service
+ windows creds (fwd creds)

I’ve been going around in circles, appreciate any guidance here folks.

**Router service configuration: **

ServiceHost serviceHost = new ServiceHost(typeof(RoutingService), new Uri[] { new Uri($"https://{routerHost}/routingservice/router") });

CustomBinding routerBinding = new CustomBinding();
routerBinding.Elements.Add(new ReliableSessionBindingElement
{
    InactivityTimeout = TimeSpan.FromMinutes(22)
});
routerBinding.Elements.Add(new HttpsTransportBindingElement
{
    AuthenticationScheme = AuthenticationSchemes.Anonymous,
    MaxReceivedMessageSize = 100000000,
    MaxBufferPoolSize = 40000000,
});

ServiceEndpoint endpoint = serviceHost.AddServiceEndpoint(typeof(IRequestReplyRouter), routerBinding, string.Empty);
endpoint.Behaviors.Add(new MessageLogger("Router"));

The client endpoint the router will route messages to

 CustomBinding remoteServiceBinding = new CustomBinding();
 remoteServiceBinding.Elements.Add(
     new ReliableSessionBindingElement
     {
         MaxRetryCount = 15,
         Ordered = true,
         InactivityTimeout = TimeSpan.FromMinutes(22)
     });
 remoteServiceBinding.Elements.Add(
     new HttpsTransportBindingElement
     {
         AuthenticationScheme = AuthenticationSchemes.Negotiate,
         MaxReceivedMessageSize = 100000000,
         MaxBufferPoolSize = 40000000,
     });

 EndpointAddress clientAddress = new EndpointAddress("https://<remoteservice url>");
 ContractDescription contract = ContractDescription.GetContract(typeof(IRequestReplyRouter));
 ServiceEndpoint client = new ServiceEndpoint(contract, remoteServiceBinding, clientAddress);

 List<ServiceEndpoint> endpointList = new List<ServiceEndpoint>() { client };

RoutingConfiguration rc = new RoutingConfiguration(){ RouteOnHeadersOnly = true };
rc.FilterTable.Add(new MatchAllMessageFilter(), endpointList);


 //attach the behavior to the service host
 serviceHost.Description.Behaviors.Add(new RoutingBehavior(rc));
 serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpsGetEnabled = true });
 var serviceAuthorizationBehavior = serviceHost.Description.Behaviors.Find<ServiceAuthorizationBehavior>();
 if (serviceAuthorizationBehavior != null)
 {
     serviceAuthorizationBehavior.ImpersonateCallerForAllOperations = true;
 }

**Client configuration snippet **

NetworkCredential remoteCred = <remote machine domain, username, password>
this.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
this.ClientCredentials.Windows.ClientCredential = remoteCred;

I tried

  • message inspectors to inject some security context/headers during BeforeSendRequest
  • other bindings on the router to pass client credentials on the message.
  • Custom ServiceAuthorization manager
  • Passing the credentials using AddBindingParameters (customize Endpoint behavior).
  • Messing around with OperationContextScope and ServiceSecurityContext.Current.

Clearly, I’m just trying out hacks…

New contributor

Ingmar H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật