1

我想知道你是否认为统一可以实现这一点或类似的事情?我想为我在当前项目中使用的 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);
    }
}
4

1 回答 1

1

好的,我有一个修复.. 我将创建我的服务引用的部分类并添加一个新的构造函数,它将 ClientCredential 的登录凭据作为参数,然后我可以像普通字符串参数一样注入!

于 2013-06-20T15:05:40.593 回答