gpt4 book ai didi

c# - 从 C# 调用 Windows 认证的 WCF 服务

转载 作者:太空狗 更新时间:2023-10-29 21:48:41 25 4
gpt4 key购买 nike

我们有一个经过 Windows 身份验证的 WCF 服务。绑定(bind)配置如下。

<basicHttpBinding>
<binding textEncoding="utf-8" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>

我正在尝试从测试应用程序中调用该服务,

try
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.ReceiveTimeout = new TimeSpan(10, 10, 00);
binding.SendTimeout = new TimeSpan(10, 10, 00);
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress endpoint = new EndpointAddress("ServiceUrl");

ChannelFactory<ICRMConnectorService> channelFactory = new ChannelFactory<ICRMConnectorService>(binding, endpoint);
channelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
var service = channelFactory.CreateChannel();

service.TestMethod();
}
catch (Exception ex)
{
throw ex;
}

调用返回一个错误,远程服务器返回错误:(401) 未经授权。

有人可以帮忙吗?

最佳答案

您可以从 ServiceReference(已添加到您的应用程序中)创建一个client 对象来调用方法,并且您可以在其中提供 windows 凭据以访问 web 服务。

对于实际实现试试这个:WCF Service, Windows Authentication

关于c# - 从 C# 调用 Windows 认证的 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47347871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com