Ejemplo n.º 1
0
        /// <summary>
        /// This Service returns the Servers known to a Server or Discovery Server.
        /// </summary>
        /// <param name="request">a request.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        /// <seealso href="https://reference.opcfoundation.org/v104/Core/docs/Part4/5.4.2/">OPC UA specification Part 4: Services, 5.4.2</seealso>
        public static async Task <FindServersResponse> FindServersAsync(FindServersRequest request, ILoggerFactory?loggerFactory = null, UaApplicationOptions?options = null)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var client = new UaTcpDiscoveryService(
                new EndpointDescription
            {
                EndpointUrl       = request.EndpointUrl,
                SecurityMode      = MessageSecurityMode.None,
                SecurityPolicyUri = SecurityPolicyUris.None
            },
                loggerFactory,
                options);

            try
            {
                await client.OpenAsync().ConfigureAwait(false);

                var response = await client.innerChannel.RequestAsync(request).ConfigureAwait(false);

                await client.CloseAsync().ConfigureAwait(false);

                return((FindServersResponse)response);
            }
            catch (Exception)
            {
                await client.AbortAsync().ConfigureAwait(false);

                throw;
            }
        }
Ejemplo n.º 2
0
        // The overriden For methods below create Log entries specific to all OPC UA
        // service request types.

        public static LogEntry For(FindServersRequest request)
        {
            LogEntry entry = new LogEntry("FindServersRequest");

            entry.Add("RequestHeader", For(request.RequestHeader));
            entry.Add("LocaleIds", For(request.LocaleIds));
            entry.Add("ServerURIs", For(request.ServerUris));
            return(entry);
        }
Ejemplo n.º 3
0
        public async Task <FindServersResponse> FindServersAsync(FindServersRequest findServersRequest)
        {
            UpdateRequestHeader(findServersRequest, true, "FindServers");
            FindServersResponse findServersResponse = null;

            try
            {
                if (UseTransportChannel)
                {
                    var serviceResponse = await Task <IServiceResponse> .Factory.FromAsync(TransportChannel.BeginSendRequest, TransportChannel.EndSendRequest, findServersRequest, null).ConfigureAwait(false);

                    if (serviceResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    ValidateResponse(serviceResponse.ResponseHeader);
                    findServersResponse = (FindServersResponse)serviceResponse;
                }
                else
                {
                    var findServersResponseMessage = await Task <FindServersResponseMessage> .Factory.FromAsync(InnerChannel.BeginFindServers, InnerChannel.EndFindServers, new FindServersMessage(findServersRequest), null).ConfigureAwait(false);

                    if (findServersResponseMessage == null || findServersResponseMessage.FindServersResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    findServersResponse = findServersResponseMessage.FindServersResponse;
                    ValidateResponse(findServersResponse.ResponseHeader);
                }
            }
            finally
            {
                RequestCompleted(findServersRequest, findServersResponse, "FindServers");
            }
            return(findServersResponse);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Begins an asynchronous invocation of the FindServers service.
        /// </summary>
        public IAsyncResult BeginFindServers(
            RequestHeader    requestHeader,
            string           endpointUrl,
            StringCollection localeIds,
            StringCollection serverUris,
            AsyncCallback    callback,
            object           asyncState)
        {
            FindServersRequest request = new FindServersRequest();

            request.RequestHeader = requestHeader;
            request.EndpointUrl   = endpointUrl;
            request.LocaleIds     = localeIds;
            request.ServerUris    = serverUris;

            UpdateRequestHeader(request, requestHeader == null, "FindServers");

            if (UseTransportChannel)
            {
                return TransportChannel.BeginSendRequest(request, callback, asyncState);
            }

            return InnerChannel.BeginFindServers(new FindServersMessage(request), callback, asyncState);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Invokes the FindServers service.
        /// </summary>
        public virtual ResponseHeader FindServers(
            RequestHeader                        requestHeader,
            string                               endpointUrl,
            StringCollection                     localeIds,
            StringCollection                     serverUris,
            out ApplicationDescriptionCollection servers)
        {
            FindServersRequest request = new FindServersRequest();
            FindServersResponse response = null;

            request.RequestHeader = requestHeader;
            request.EndpointUrl   = endpointUrl;
            request.LocaleIds     = localeIds;
            request.ServerUris    = serverUris;

            UpdateRequestHeader(request, requestHeader == null, "FindServers");

            try
            {
                if (UseTransportChannel)
                {
                    IServiceResponse genericResponse = TransportChannel.SendRequest(request);

                    if (genericResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    ValidateResponse(genericResponse.ResponseHeader);
                    response = (FindServersResponse)genericResponse;
                }
                else
                {
                    FindServersResponseMessage responseMessage = InnerChannel.FindServers(new FindServersMessage(request));

                    if (responseMessage == null || responseMessage.FindServersResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    response = responseMessage.FindServersResponse;
                    ValidateResponse(response.ResponseHeader);
                }

                servers = response.Servers;
            }
            finally
            {
                RequestCompleted(request, response, "FindServers");
            }

            return response.ResponseHeader;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes the message with the body.
 /// </summary>
 public FindServersMessage(FindServersRequest FindServersRequest)
 {
     this.FindServersRequest = FindServersRequest;
 }