3

我尝试使用此页面上提供的客户端连接到 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 Server 不支持的 Block Read 和 Block Write。所以这个应用程序将不起作用。

4

2 回答 2

2

这个 Siemens UaClient 使用一个库“ClientAPI”,它扩展了 OPC Foundation 的 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:

从跟踪日志中,您可能会发现证书错误。创建新会话时,客户端和服务器都提供并验证彼此的证书。默认情况下,UaClient 正在从 Windows 存储 LocalMachine\My(又名 Personal)中检索它的证书。api 在首次运行期间生成此证书(需要以管理员身份首次运行)(要查看此证书,请运行“certlm.msc”)。

在服务器机器上,服务器将验证客户端的证书,方法是检查它是否匹配其“TrustedPeerList”中的证书。服务器通常使用目录来存储受信任的证书。如果客户端证书不受信任,服务器会将客户端证书复制到“RejectedCertificates”目录。您需要将在“RejectedCertificates”中找到的证书复制到受信任的证书目录。

回到客户端机器上,客户端将验证服务器的证书。此客户端使用 Windows 商店验证“LocalMachine\My”(又名个人)。客户端不使用“拒绝”目录,而是注册一个事件处理程序,该处理程序打开一个消息框,询问您是否希望接受服务器的证书。如果选择接受,客户端设置 eventArg e.Accept = true; 要抑制消息框,应使用工具“certlm.msc”将服务器的证书导入客户端的“LocalMachine\My”(又名“个人”)。

于 2016-02-02T16:55:18.793 回答
0

尝试使用 DNS 名称 ping 服务器。如果服务器不可访问,则必须编辑 C:\Windows\System32\drivers\etc... 中的 Hosts 文件。以管理员身份打开记事本,然后打开Hosts文件,输入IP地址到主机名的映射如下:

xxx.xxx.xxx.xxx 主机名

于 2017-04-26T07:47:32.037 回答