我尝试使用此页面上提供的客户端连接到OPC UA服务器:https://support.industry.siemens.com/cs/document/42014088/programming-an-opc-ua-net-client-with-c%23-for-the-simatic-net-opc-ua-server?dti=0&lc=en-US。使用Siemens OPC Scount v10连接OPC UA服务器工作正常。使用本文中提供的客户端连接到OPC UA服务器时,我收到以下消息:
无法打开UA TCP请求频道。
异常的堆栈跟踪是这样的:
Server stack trace:
at Opc.Ua.Bindings.UaTcpRequestChannel.OnEndOpen(IAsyncResult result)
at Opc.Ua.Bindings.UaTcpRequestChannel.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)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Opc.Ua.ISessionChannel.CreateSession(CreateSessionMessage request)
at Opc.Ua.SessionChannel.CreateSession(CreateSessionMessage request)
at Opc.Ua.SessionClient.CreateSession(RequestHeader requestHeader, ApplicationDescription clientDescription, String serverUri, String endpointUrl, String sessionName, Byte[] clientNonce, Byte[] clientCertificate, Double requestedSessionTimeout, UInt32 maxResponseMessageSize, NodeId& sessionId, NodeId& authenticationToken, Double& revisedSessionTimeout, Byte[]& serverNonce, Byte[]& serverCertificate, EndpointDescriptionCollection& serverEndpoints, SignedSoftwareCertificateCollection& serverSoftwareCertificates, SignatureData& serverSignature, UInt32& maxRequestMessageSize)
at Opc.Ua.Client.Session.Open(String sessionName, UInt32 sessionTimeout, IUserIdentity identity, IList`1 preferredLocales)
at Opc.Ua.Client.Session.Open(String sessionName, IUserIdentity identity)
任何帮助将不胜感激。 OPC UA服务器在Siemens Simatic HMI TP700 Comfort上运行。 OPC UA服务器上的配置是默认配置。
在andrewcullen提示之后,我们在tracelog.txt文件中获取以下日志并在捕获显示
的异常时出错连接服务器时发生意外错误。
PID:4196 ************************* Logging started at 02/03/2016 07:41:34 *************************
4196 - 07:41:38.742 GetEndpoints Called. RequestHandle=1, PendingRequestCount=1
4196 - 07:41:38.992 SECURE CHANNEL CREATED [TcpClientChannel UA-TCP 1.00.238.1] [ID=12752] Connected To: opc.tcp://xxx.xxx.xxx.xxx:4870/
4196 - 07:41:39.008 TCPCLIENTCHANNEL SOCKET CONNECTED: 00000698, ChannelId=12752
4196 - 07:41:39.008 SECURE CHANNEL CREATED [Opc.Ua.ChannelBase WCF Client 1.00.238.1] [ID=] Connected To: opc.tcp://xxx.xxx.xxx.xxx:4870/
4196 - 07:41:39.101 GetEndpoints Completed. RequestHandle=1, PendingRequestCount=0
4196 - 07:41:39.132 TCPCLIENTCHANNEL SOCKET CLOSED: 00000698, ChannelId=12752
4196 - 07:41:44.230 Writing rejected certificate to directory:
4196 - 07:41:59.694 CreateSession Called. RequestHandle=1, PendingRequestCount=1
4196 - 07:42:13.672 TCPCLIENTCHANNEL SOCKET CLOSED: 000007C0, ChannelId=0
4196 - 07:42:13.750 CreateSession Completed. RequestHandle=1, PendingRequestCount=0
我得到了西门子官方支持的答复:
应用程序未使用Comfort Panel进行测试。代码,例如包含Panel Read和Block Write,Panel Server不支持。 所以这个应用程序将无法运行。
答案 0 :(得分:2)
此西门子UaClient使用库' ClientAPI'它扩展了OPC基金会的Opc.Ua.Core和Opc.Ua.Client。 ClientAPI有很多很好的Helper函数来简化连接和订阅。但是,我在Connect(String Url)的代码中看到它正在使用原始的WCF样式的通道。并且您的堆栈跟踪显示WCF类型正在抛出难以诊断的异常。我会改变两件事:
首先配置跟踪以写入文件。在ClientAPI中,找到Helpers.CreateClientConfiguration()并添加
// add trace config before calling validate
configuration.TraceConfiguration = new TraceConfiguration {
OutputFilePath="tracelog.txt",
DeleteOnLoad = true,
TraceMasks = Utils.TraceMasks.All };
configuration.Validate(ApplicationType.Client);
其次,升级用于连接的通道类型。在ClientAPI中,找到Server.Connect(string url)并修改中间,如下所示:
// Initialize the channel which will be created with the server.
// SessionChannel channel = SessionChannel.Create(
// configuration,
// endpointDescription,
// endpointConfiguration,
// bindingFactory,
// clientCertificate,
// null);
ITransportChannel channel = WcfChannelBase.CreateUaBinaryChannel(
configuration,
endpointDescription,
endpointConfiguration,
clientCertificate,
configuration.CreateMessageContext());
// Wrap the channel with the session object.
// This call will fail if the server does not trust the client certificate.
// m_Session = new Session(channel, configuration, endpoint);
m_Session = new Session(channel, configuration, endpoint, clientCertificate);
编辑2/4:
从tracelog中,您可能会发现证书错误。创建新会话时,客户端和服务器都提供并验证彼此的证书。默认情况下,UaClient正在从Windows商店LocalMachine \ My(又名个人)中检索它的证书。 api在首次运行期间生成此证书(需要以管理员身份首次运行)(要查看此证书,请运行' certlm.msc')。
在服务器计算机上,服务器将验证客户端的证书,检查它是否与其“TrustedPeerList”中的证书匹配。服务器通常使用目录来存储受信任的证书。如果客户端证书不受信任,则服务器会将客户端证书复制到“已拒绝的证书”中。目录。您需要复制在“被拒绝的证书”中找到的证书。到受信任的证书目录。
返回客户端计算机,客户端将验证服务器的证书。此客户端使用Windows商店进行验证' LocalMachine \ My' (又名个人)。 而不是使用'拒绝'在目录中,客户端注册一个打开消息框的事件处理程序,询问您是否希望接受服务器的证书。如果您选择接受,客户端会设置eventArg e.Accept = true;要取消显示消息框,应将服务器的证书导入客户端的LocalMachine \ My' (又名个人)使用工具' certlm.msc'。
答案 1 :(得分:0)
尝试使用DNS名称ping服务器。如果无法访问服务器,则必须编辑C:\ Windows \ System32 \ drivers \ etc ...中的Hosts文件。以管理员身份打开记事本,然后打开Hosts文件并输入IP地址到主机名的映射,如下所示:
xxx.xxx.xxx.xxx主机名