0

我在 Azure 上有一个向 Azure Relay 发送请求的 WebAapp。它应该传输到需要基本身份验证的 IIS 上托管的本地 WCF HTTPS 服务的侦听器。如何通过 Azure Relay 发送 onprem WCF 服务的授权基本标头。我该如何发送?例子,

“授权”:“基本239837987XYC”

我用过通道工厂,

        var  ChannelFactory<Overview.MyChannel> cf;
        var relayNamespace ="myrelaynamespace";
        var relayListener = "myrelaylistener";
        var endPointAddress = new EndpointAddress(ServiceBusEnvironment.CreateServiceUri("https", relayNamespace, relayListener));
        cf = new ChannelFactory<Overview.ItServiceManagementAOChannel>(binding, endPointAddress);
        ClientCredentials loginCredentials = new ClientCredentials();
        loginCredentials.UserName.UserName = "onpremWCFusername";
        loginCredentials.UserName.Password = "onpremWCFpassword";

        cf.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior
        {
            TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(ConfigurationManager.AppSettings.Get("WcfRelayKeyName"), ConfigurationManager.AppSettings.Get("WcfRelayKey"))
        });
        cf.Endpoint.Behaviors.Add(loginCredentials); 

我收到错误:无法将值添加到集合中,因为集合已包含相同类型的项目:“System.ServiceModel.Description.ClientCredentials”。此集合仅支持每种类型的一个实例。参数名称:项目

   using (var ch = cf.CreateChannel())
        {
           try
            {
               var resp = ch.CreateTaskAsync(req).Result;
            }
         }
4

1 回答 1

0

尝试将 Windows 凭据指定为客户端凭据。

factory.Credentials.Windows.ClientCredential.UserName = "administrator";
factory.Credentials.Windows.ClientCredential.Password = "123456";
IService sv = factory.CreateChannel();

如果问题仍然存在,请随时告诉我。

于 2018-11-27T07:11:59.657 回答