我不得不将一个WCF服务的调用变成一个传统的VB6应用程序。为此,我引用了一个c#dll来调用wcf方法。在dll中,我正在设置配置,而不是使用配置文件。当我运行我的单元测试的dll工作,但一旦我的VB6应用程序中执行它,我收到以下错误:WCF(401)未经授权引用dll时
System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest. WaitForReply(TimeSpan timeout) The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Negotiate,NTLM,Basic realm=[the ip]
该服务使用基本身份验证。在这两种情况下,我都使用相同的网址,用户名和密码。这是我做的代码中的配置:
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];
}
我想不通,当它被用VB6应用程序执行的是不同的。任何输入赞赏。
运行VB6应用程序的凭据是什么? – Tim 2012-01-27 05:55:08
进一步提姆的问题。 VB6应用程序是否作为服务运行?它是COM组件还是在COM +/Component服务中运行?它是否由另一个应用程序启动? – Zippit 2012-01-27 06:04:21
尝试对您的服务启用跟踪并检查消息头的跟踪日志,以查找在您从单元测试调用时以及从VB6应用调用时正在传递的用户名/密码。这应该告诉你为什么你会得到401错误 – Rajesh 2012-01-27 12:05:43