如何通过 azure relay C# 为 prem wcf https 服务发送基本身份验证凭据?
How do I send basic authentication credentials for a prem wcf https service over azure relay C#?
我在 Azure 上有一个 WebAapp,它向 Azure Relay 发送请求。它应该传输到托管在需要基本身份验证的 IIS 上的本地 WCF HTTPS 服务的侦听器。如何通过 Azure Relay 为 onprem WCF 服务发送基本授权 header。我该如何发送?例如,
"Authorization": "Basic 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);
我收到错误:无法将值添加到 collection,因为 collection 已经包含相同类型的项目:'System.ServiceModel.Description.ClientCredentials'。 collection 每种类型只支持一个实例。
参数名称:item
using (var ch = cf.CreateChannel())
{
try
{
var resp = ch.CreateTaskAsync(req).Result;
}
}
尝试将 windows 凭据指定为客户端凭据。
factory.Credentials.Windows.ClientCredential.UserName = "administrator";
factory.Credentials.Windows.ClientCredential.Password = "123456";
IService sv = factory.CreateChannel();
如果问题仍然存在,请随时告诉我。
我在 Azure 上有一个 WebAapp,它向 Azure Relay 发送请求。它应该传输到托管在需要基本身份验证的 IIS 上的本地 WCF HTTPS 服务的侦听器。如何通过 Azure Relay 为 onprem WCF 服务发送基本授权 header。我该如何发送?例如,
"Authorization": "Basic 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);
我收到错误:无法将值添加到 collection,因为 collection 已经包含相同类型的项目:'System.ServiceModel.Description.ClientCredentials'。 collection 每种类型只支持一个实例。 参数名称:item
using (var ch = cf.CreateChannel())
{
try
{
var resp = ch.CreateTaskAsync(req).Result;
}
}
尝试将 windows 凭据指定为客户端凭据。
factory.Credentials.Windows.ClientCredential.UserName = "administrator";
factory.Credentials.Windows.ClientCredential.Password = "123456";
IService sv = factory.CreateChannel();
如果问题仍然存在,请随时告诉我。