我不得不將一個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