【发布时间】:2013-11-30 12:37:47
【问题描述】:
所以我写了一个小游戏,希望这个游戏可以在互联网上玩。
我一直在使用这些配置通过 localhost 测试游戏:
客户端 Winapp 应用程序:
App.Config 文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<client>
<endpoint name ="CommandBoard"
address="net.tcp://localhost:9000/commandboard"
binding = "netTcpBinding"
contract="CommandBoardServiceLibrary.ICommandBoardService"/>
</client>
</system.serviceModel>
</configuration>
在客户端 Winform 代码中我有它像这样连接
ChannelFactory<ICommandBoardService> remoteFactory= new ChannelFactory<ICommandBoardService>("CommandBoard");
ICommandBoardService proxy = remoteFactory.CreateChannel();
接下来,为了托管服务,我创建了一个控制台应用程序。
App.config 是基本的。我没有改变任何东西,只是在实际代码中。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
控制台应用代码:
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(CommandBoardServiceLibrary.CommandBoardService)))
{
host.AddServiceEndpoint(typeof(
CommandBoardServiceLibrary.ICommandBoardService),
new NetTcpBinding(),
"net.tcp://localhost:9000/commandboard");
host.Open();
Console.ReadLine();
}
}
同时运行客户端和主机在我的计算机上完美运行。
现在当我将客户端的 App.Config 更改为
<client>
<endpoint name ="CommandBoard"
address="net.tcp://23.122.59.211:9000/commandboard"
binding = "netTcpBinding"
contract="CommandBoardServiceLibrary.ICommandBoardService"/>
</client>
并在不同网络上的不同计算机上运行它,我收到以下错误:
System.ServiceModel.Security.SecurityNegotiationException: The server has rejected the client credentials. ---> System.Security.Authentication.InvalidCredentialException: The server has rejected the client credentials. ---> System.ComponentModel.Win32Exception: The logon attempt failed
这个错误的根源在哪里?是否配置不正确?还是我错过了什么?
编辑:WCF 服务的 Web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
【问题讨论】:
-
服务器的 WCF 配置是什么?
-
@Szymon 我怎样才能为您找到它?我刚开始学习WCF,所以对所有东西的布局都不太习惯。您是否在我的 CommandBoardServiceLibrary 中寻找 Web.Config 文件?
-
它是定义安全要求的服务器。是的,就是服务器的web.config。
-
-
@Szymon,你还介意帮我吗?
标签: c# wcf exception networking network-programming