C# 使用unity依赖项注入容器在MVC项目中设置WCF客户端凭据
我想知道你是否认为这件事或类似的事情在团结中是可能的?我想为当前项目中使用的WCF服务引用OrderServiceClientClient()注入用户名和密码凭据C# 使用unity依赖项注入容器在MVC项目中设置WCF客户端凭据,c#,wcf,dependency-injection,unity-container,C#,Wcf,Dependency Injection,Unity Container,我想知道你是否认为这件事或类似的事情在团结中是可能的?我想为当前项目中使用的WCF服务引用OrderServiceClientClient()注入用户名和密码凭据 container.RegisterType<IOrderServiceClient, OrderServiceClientClient>( new InjectionConstructor( new InjectionProperty("ClientCredentials.UserName.UserNa
container.RegisterType<IOrderServiceClient, OrderServiceClientClient>(
new InjectionConstructor(
new InjectionProperty("ClientCredentials.UserName.UserName", "test"),
new InjectionProperty("ClientCredentials.UserName.Password", "password")));
container.RegisterType(
新注入构造函数(
新的InjectionProperty(“ClientCredentials.UserName.UserName”,“test”),
新的InjectionProperty(“ClientCredentials.UserName.Password”、“Password”);
这样的事情可能吗
编辑:
查看服务引用,该类的定义如下所示:
class ProductMasterServiceClientClient : System.ServiceModel.ClientBase<com.luzern.co40.web.pm.wsProductMasterService.IProductMasterServiceClient>, com.luzern.co40.web.pm.wsProductMasterService.IProductMasterServiceClient
类别ProductMasterServiceClientClient:System.ServiceModel.ClientBase,com.luzern.co40.web.pm.wsProductMasterService.ipProductMasterServiceClient
父类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);
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.ServiceModel”,“4.0.0.0”)]
公共部分类OrderServiceClientClient:System.ServiceModel.ClientBase,com.luzern.co40.web.pm.wsOrderService.IOrderServiceClient{
public OrderServiceClientClient(){
}
public OrderServiceClientClient(字符串endpointConfigurationName):
基本(endpointConfigurationName){
}
public OrderServiceClientClient(字符串endpointConfigurationName,字符串remoteAddress):
基本(endpointConfigurationName,remoteAddress){
}
public OrderServiceClientClient(字符串endpointConfigurationName,System.ServiceModel.EndpointAddress remoteAddress):
基本(endpointConfigurationName,remoteAddress){
}
public OrderServiceClientClient(System.ServiceModel.Channel.Binding绑定,System.ServiceModel.EndpointAddress remoteAddress):
基址(绑定、远程地址){
}
public bool GenerateInvoice(int-orderId,string-email){
返回base.Channel.GenerateInvoice(订单ID,电子邮件);
}
public System.Threading.Tasks.Task GenerateInvoiceAsync(int-orderId,字符串电子邮件){
返回base.Channel.GenerateInvoiceAsync(订单ID,电子邮件);
}
}
好的,我有一个解决方案。。我将创建我的服务引用的一个部分类,并添加一个新的构造函数,该构造函数将ClientCredential的登录凭据作为参数,然后我可以作为普通字符串参数进行插入 好的,我有一个解决办法。。我将创建我的服务引用的一个部分类,并添加一个新的构造函数,该构造函数将ClientCredential的登录凭据作为参数,然后我可以作为普通字符串参数进行插入 你能给我们看一下OrderServiceClientClient类和相关对象的代码吗?这是从WCF服务生成的服务引用我在上面做了编辑!谢谢您仍然没有显示OrderServiceClientClient的代码…很抱歉,我已经添加了它。您可以向我们显示OrderServiceClientClient类和相关对象的代码吗?这是从WCF服务生成的服务引用我在上面进行了编辑!谢谢您仍然没有显示OrderServiceClientClient的代码…很抱歉,我在那里添加了它