[英]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.