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'.
我在这里错过了什么?