我在 Windows 7 上开发了一个带有 WCF REST 和 TCP(角色间)端点的项目。我刚刚升级到 Windows 8,现在我遇到了严重的问题。
首先,当我将项目部署到 azure 时,会收到以下警告:
Windows Azure Tools: Warning: Remapping private port 80 to 81 in role 'OfisimCRM.WebClient' to avoid conflict during emulation.
Windows Azure Tools: Warning: Remapping private port 443 to 446 in role 'OfisimCRM.WebClient' to avoid conflict during emulation.
Skype 已禁用,这不是问题。
这不是那么重要,但重要的是我从我的交互通信请求中得到了更严重的错误,尽管我完全禁用了防火墙。这里是:
Could not connect to net.tcp://127.255.0.0:22000/NotifyService. The connection attempt lasted for a time span of 00:00:01.1820716. TCP error code 10061: No connection could be made because the target machine actively refused it 127.255.0.0:22000. -
Server stack trace:
at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
at System.ServiceModel.Channels.BufferedConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
TCP客户端代码:
public static LicenseItem CheckLicense(int userID)
{
// This instance does not exist in memory cache. Check if other servers in the same web role know anything about this instance.
var webRoles = RoleEnvironment.Roles["OfisimCRM.WebClient"];
var myID = RoleEnvironment.CurrentRoleInstance.Id;
LicenseItem remoteValue = null;
foreach (var targetInstance in webRoles.Instances)
{
// I am currently going through a loop of instances. Check if the current enumaration shows my address.
if (targetInstance.Id == myID)
{
// Skip.
}
else
{
// This is a neighbour instance. Check to see if it knows about the instance I'm looking for.
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
EndpointAddress targetAddress = new EndpointAddress(
String.Format("net.tcp://{0}/NotifyService", targetInstance.InstanceEndpoints["NotificationServiceEndPoint"].IPEndpoint)
);
ChannelFactory<INotifyService> channelFactory = new ChannelFactory<INotifyService>(binding, targetAddress);
INotifyService targetClient = channelFactory.CreateChannel();
try
{
remoteValue = targetClient.CheckLicense(userID);
if (channelFactory.State != System.ServiceModel.CommunicationState.Faulted)
{
channelFactory.Close();
}
}
catch (TimeoutException timeoutException)
{
Trace.TraceError("Unable to check license on web role instance '{0}'. The service operation timed out. {1}", myID, timeoutException.Message);
((ICommunicationObject)targetClient).Abort();
}
catch (CommunicationException communicationException)
{
Trace.TraceError("Unable to check instance on web role instance '{0}'. There was a communication problem. {1} - {2}", myID, communicationException.Message, communicationException.StackTrace);
((ICommunicationObject)targetClient).Abort();
}
}
}
return remoteValue;
}
编辑 1:重要更新:
我认为问题在于第二个实例。我做了一个调试,我看到连接只被这个停止的实例拒绝。我认为这解释了一切,但我不知道为什么会这样。
编辑 2:临时解决方案:
我注意到这不是关于 Windows 8 的问题,因为我将 Azure SDK June 2012 SP1 升级到了 2012 年秋季。我从 TFS 下载了我的项目的未升级版本,而不是我看到它正在工作。总之,它是 Azure SDK,但我不知道为什么。