1
我正在遷移服務引用以使用通道工廠。遷移到Channel Factory的服務引用
我將接口從服務實現分離到單獨的類庫中。
- IIb類:
IService
- IIb類:
Service
- Web應用程序:參考
IService
代碼:
配置
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingEndpoint" maxReceivedMessageSize="5242880">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
類:
public class ProxyManager
{
internal static ConcurrentDictionary<string, ChannelFactory<IService>> proxies = new ConcurrentDictionary<string, ChannelFactory<IService>>();
internal static ChannelFactory<IService> CreateChannelFactory()
{
Global.Logger.Info("ProxyManager:CreateChannelFactory");
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
basicHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
EndpointAddress endpointAddress = new EndpointAddress("http://domain/Service.svc");
var channelFactory = new ChannelFactory<IService>(basicHttpBinding, endpointAddress);
channelFactory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
return channelFactory;
}
internal static IService GetProxy(string key)
{
Global.Logger.Info("ProxyManager:GetProxy");
return proxies.GetOrAdd(key, m => CreateChannelFactory()).CreateChannel();
}
internal static bool RemoveProxy(string key)
{
Global.Logger.Info("ProxyManager:RemoveProxy");
ChannelFactory<IService> proxy;
return proxies.TryRemove(key, out proxy);
}
}
全球:
public static IService ServiceProxy
{
get
{
return ProxyManager.GetProxy("Service");
}
}
用法:
ServiceProxy.Method();
錯誤:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
我在這裏錯過了什麼?