简体   繁体   English

引用Dll时未经授权的WCF(401)

[英]WCF (401) Unauthorized When Referencing Dll

I have to shoe horn a call to a WCF service into a legacy VB6 app. 我必须对旧版VB6应用程序中的WCF服务进行呼叫。 To do this, I'm referencing ac# dll to call the wcf method. 为此,我引用ac#dll来调用wcf方法。 In the dll I'm setting the configuration as opposed to using a config file. 在dll中,我正在设置配置,而不是使用配置文件。 The dll works when I run my unit tests, but once I execute it within the vb6 app, I get the following error: 当我运行单元测试时,dll可以工作,但是一旦在vb6应用程序中执行了该dll,就会出现以下错误:

System.Net.WebException: The remote server returned an error: (401) Unauthorized. System.Net.WebException:远程服务器返回错误:(401)未经授权。 at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest. 在System.Net.HttpWebRequest.GetResponse()处在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest中。 WaitForReply(TimeSpan timeout) The HTTP request is unauthorized with client authentication scheme 'Basic'. WaitForReply(TimeSpan timeout)使用客户端身份验证方案“基本”对HTTP请求进行未经授权的操作。 The authentication header received from the server was 'Negotiate,NTLM,Basic realm=[the ip] 从服务器收到的身份验证标头是'Negotiate,NTLM,Basic realm = [ip]

The service is using basic authentication. 该服务正在使用基本身份验证。 In both scenarios I'm using the same url, username, and password. 在这两种情况下,我都使用相同的url,用户名和密码。 Here is the configuration I'm doing in code: 这是我在代码中所做的配置:

    BasicHttpBinding binding = new BasicHttpBinding
{
    SendTimeout = TimeSpan.FromMinutes(1),
    OpenTimeout = TimeSpan.FromMinutes(1),
    CloseTimeout = TimeSpan.FromMinutes(1),
    ReceiveTimeout = TimeSpan.FromMinutes(10),
    AllowCookies = false,
    BypassProxyOnLocal = false,
    HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
    MessageEncoding = WSMessageEncoding.Mtom,
    TextEncoding = System.Text.Encoding.UTF8,
    TransferMode = TransferMode.Buffered,
    UseDefaultWebProxy = true,
};

binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

var wcf = new [servicename](binding, new EndpointAddress([the url]));

if (wcf .ChannelFactory.Credentials != null)
{                
    wcf .ChannelFactory.Credentials.UserName.UserName = [the username];
    wcf .ChannelFactory.Credentials.UserName.Password = [the pw];
}

I can't figure out what is different when it gets executed by the VB6 app. 当VB6应用程序执行它时,我不知道有什么不同。 Any input is appreciated. 任何输入表示赞赏。

The C# DLL is registered for com interop. C#DLL已注册用于com互操作。 I had assumed it was a byproduct of being called through vb6, but I took at step back and realized the wcf credentials were being provided correctly by the vb6, but the code path it followed in the dll was slightly different and they weren't being applied correctly. 我以为这是通过vb6调用的副产品,但我退后一步意识到,vb6正确提供了wcf凭据,但是它在dll中遵循的代码路径略有不同,因此并不是正确应用。

Always seems to be that when things make no sense at all, some underlying assumption is wrong. 似乎总是总是当事情毫无意义时,某些基本假设是错误的。 Thanks for the suggestions. 感谢您的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新WCF服务参考时出现401未经授权的错误 - 401 Unauthorized error when updating WCF service reference 在IIS上尝试我的WCF数据服务时得到“401 - 未经授权” - Got a “401 - Unauthorized” when trying my WCF Data service on IIS WCF错误401仅在某些PC上未经授权 - WCF Error 401 Unauthorized only on some pcs 将文件字节流发送到WCF服务时,为什么会出现“ 401-未经授权”错误? - Why am I getting a “401 - Unauthorized” error when sending a file byte stream to a WCF service? 401仅在服务器上时未经授权 - 401 Unauthorized only when on server 从另一个WCF服务调用时,WCF Web服务IIS6 401未授权错误。 从asmx / WinForms调用可以 - WCF web service IIS6 401 unauthorized error when calling from another WCF service. Calling from asmx/WinForms is OK 使用基本身份验证调试本地WCF服务始终返回401-未经授权 - Debug local WCF service with Basic Authentication always returns 401 - Unauthorized 从自定义基本身份验证WCF中显示401未经授权的错误 - Show 401 unauthorized error from custom basic authentication wcf WCF Rest 自托管证书安全服务返回 401 未经授权 - WCF Rest self hosted certificate secured service returns 401 unauthorized 远程服务器返回错误:(401)未经授权。 wcf httpbinding基本 - The remote server returned an error: (401) Unauthorized. wcf httpbinding basic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM