我想知道你是否认为统一可以实现这一点或类似的事情?我想为我在当前项目中使用的 WCF 服务参考 OrderServiceClient() 注入用户名和密码凭据。
container.RegisterType<IOrderServiceClient, OrderServiceClientClient>(
new InjectionConstructor(
new InjectionProperty("ClientCredentials.UserName.UserName", "test"),
new InjectionProperty("ClientCredentials.UserName.Password", "password")));
这样的事情可能吗?
编辑:
查看服务参考,该类的定义如下所示:
class ProductMasterServiceClientClient : System.ServiceModel.ClientBase<com.luzern.co40.web.pm.wsProductMasterService.IProductMasterServiceClient>, com.luzern.co40.web.pm.wsProductMasterService.IProductMasterServiceClient
父类 ClientBase 类包含 ClientCredential 成员的定义..
我不想替换整个 ClientCredential 成员,我只想在上面设置 2 个属性用户名和密码!
编辑2!!
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class OrderServiceClientClient : System.ServiceModel.ClientBase<com.luzern.co40.web.pm.wsOrderService.IOrderServiceClient>, com.luzern.co40.web.pm.wsOrderService.IOrderServiceClient {
public OrderServiceClientClient() {
}
public OrderServiceClientClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public OrderServiceClientClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public OrderServiceClientClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public OrderServiceClientClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
public bool GenerateInvoice(int orderId, string email) {
return base.Channel.GenerateInvoice(orderId, email);
}
public System.Threading.Tasks.Task<bool> GenerateInvoiceAsync(int orderId, string email) {
return base.Channel.GenerateInvoiceAsync(orderId, email);
}
}