gpt4 book ai didi

C# - 在 Visual Studio 外部执行应用程序时出现问题

转载 作者:行者123 更新时间:2023-11-30 17:26:33 25 4
gpt4 key购买 nike

我在应用程序中执行实现时遇到问题。我有一些网络服务,我可以在 Visual Studio 中正常工作、运行和访问其信息。

与web服务地址的连接可以通过IE等方式访问,服务正常。

我在应用程序中执行可执行文件,当它试图访问 web 服务时,出现 403(禁止访问)错误。

凭据没问题,因为触发错误的行是在身份验证完成后使用 web 服务的方法。

即使在应用程序中以管理员权限运行,它也会显示相同的错误。 WCF 服务由本地管理员用户运行。

我已经尝试在使用该方法的同一范围内请求,但未成功。

private SI_Out_SyncClient WebserviceConnection ()
{

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;

binding.CloseTimeout = new TimeSpan(1, 5, 0);
binding.OpenTimeout = new TimeSpan(1, 5, 0);
binding.SendTimeout = new TimeSpan(1, 5, 0);

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;

EndpointAddress address = new EndpointAddress(Library.Environment.GetGlobalString("ENDPOINT"));

var client = new SI_Out_SyncClient(binding, address);

client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.UserName.UserName = Library.Environment.GetGlobalString("USER");
client.ClientCredentials.UserName.Password = Library.Environment.GetGlobalString("PASSWORD");

return client;
}

我希望在应用程序中运行,因为我可以在调试中运行,但以正确的方式运行,无需将调试编译模式设置为 true。

提前致谢!

最佳答案

我知道发生了什么。

在我的例子中,运行 WCF 服务的管理员用户无法访问互联网。

一个愚蠢的错误,但值得注册,因为我在研究中没有找到这样的方向。

关于C# - 在 Visual Studio 外部执行应用程序时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56330700/

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