Opc.Ua.EndpointBase.CreateSoapFault C# (CSharp) Method

CreateSoapFault() protected static method

Creates a fault message.
protected static CreateSoapFault ( IServiceRequest request, Exception exception ) : Exception
request IServiceRequest The request.
exception System.Exception The exception.
return System.Exception
        protected static Exception CreateSoapFault(IServiceRequest request, Exception exception)
        {
            ServiceFault fault = CreateFault(request, exception);

            // get the error from the header.
            ServiceResult error = fault.ResponseHeader.ServiceResult;

            if (error == null)
            {
                error = ServiceResult.Create(StatusCodes.BadUnexpectedError, "An unknown error occurred.");
            }
            
            // construct the fault code and fault reason.
            string codeName = StatusCodes.GetBrowseName(error.Code);

            FaultCode code = null;
            FaultReason reason = null;

            if (!LocalizedText.IsNullOrEmpty(error.LocalizedText))
            {
                reason = new FaultReason(new FaultReasonText(Utils.Format("{0}", error.LocalizedText)));
            }
            else
            {
                reason = new FaultReason(new FaultReasonText(codeName));
            }

            if (!String.IsNullOrEmpty(error.SymbolicId))
            {
                FaultCode subcode = new FaultCode(error.SymbolicId, error.NamespaceUri);
                code = new FaultCode(codeName, Namespaces.OpcUa, subcode);
            }
            else
            {
                code = new FaultCode(codeName, Namespaces.OpcUa);
            }

            // throw the fault.
            return new FaultException<ServiceFault>(fault, reason, code, string.Empty);
        }