使用unity依赖注入容器在MVC项目中设置WCF ClientCredentials
本文关键字:项目 设置 WCF ClientCredentials MVC 依赖 unity 注入 使用 | 更新日期: 2023-09-27 18:19:25
我想知道你是否认为这或类似的东西可能与统一?我想为WCF服务引用OrderServiceClientClient()注入用户名和密码凭据,我正在当前项目中使用。
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);
}
}
好吧,我有一个修复…我将创建我的服务引用的部分类,并添加一个新的构造函数,它将ClientCredential的登录凭据作为参数,然后我可以将其作为普通字符串参数注入!