Beispiel #1
0
        }     // CreateProxy()

        /// <summary>
        /// This method wraps the invocation of a Connection Manager call.
        /// An ICOMS tag is wrapped around the passed instance before the
        /// call is made. This function removes as much common functionality
        /// as possible form a CM call.
        /// </summary>
        /// <param name="obj">
        /// The child tag indicating a proper Connection Manager macro
        /// complete with attributes.
        /// </param>
        /// <returns>
        /// The output of this method is the corresponding output tag to the
        /// input. Of course, this is effectively managed by Connection
        /// Manager.
        /// </returns>
        protected object Invoke(object obj)
        {
            // Setup a request instance
            Request.ICOMS icomsRequest = new IcomsHelper(obj);
            // Setup and response instance holder
            Response.ICOMS icomsResponse = null;

            try
            {
                icomsResponse = m_proxy.CmMethod((Request.ICOMS)icomsRequest);
            }             // try
            catch (CmErrorException)
            {
                // Let the containing layer have a crack at this information
                throw;
            }             // catch( CmErrorException excCm )
            catch (Exception exc)
            {
                throw new ServiceAgentUnavailableException(exc);
            }             // catch( Exception exc )

            // NOTE: If Response.ERROR came back from Connection Manager, the
            // proxy would already have dealt with that above.

            return(icomsResponse.Item);
        }          // Invoke( Request.ICOMS )
        protected virtual Response.ICOMS ReceiveResponse(WebResponse rsp)
        {
            Response.ICOMS rspicoms = null;
            Stream         strm     = null;
            StreamReader   rdr      = null;

            try
            {
                strm = rsp.GetResponseStream();
                // NOTE: Cannot use XmlTextReader. It complains and gives
                // an empty string. instead use the generic StreamReader
                rdr      = new StreamReader(strm);
                rspicoms = (Response.ICOMS)ObjectSerializer.Deserialize(
                    rdr.ReadToEnd(), typeof(Response.ICOMS));

                // TODO: Trace response???
            }             // try
            catch (IOException excIo)
            {
                Debug.WriteLine(excIo);
                throw new CmUnavailableException(excIo);
            }             // catch( IOException excIo )
            catch (Exception exc)
            {
                Debug.WriteLine(exc);
                throw new CmProxyException(exc);
            }             // catch( Exception exc )
            finally
            {
                if (null != rdr)
                {
                    rdr.Close();
                }
                if (null != strm)
                {
                    strm.Close();
                }
            }             // finally

            return(rspicoms);
        }          // ReceiveResponse()
        public Response.ICOMS CmMethod(Request.ICOMS reqicoms)
        {
            // Set routing information from constructor of this proxy
            reqicoms.ENVIRONMENT = m_strEnvironment;
            reqicoms.USERID      = m_strUsername;
            reqicoms.PASSWORD    = m_strPassword;

            WebRequest req = GetWebRequest(new Uri(Url));

            SendRequest(req, reqicoms);

            WebResponse rsp = GetWebResponse(req);

            Response.ICOMS rspicoms = ReceiveResponse(rsp);
            rsp.Close();

            // Parse the standard errors
            string strErrorText = null;
            int    intErrorCode = 0;

            FindError(rspicoms.Item, out intErrorCode, out strErrorText);
            if (0 != intErrorCode)
            {
                throw new CmErrorException(intErrorCode,
                                           kstrErrorMessageDefault, new CmProxyException(strErrorText));
            }

            // If the output key was not returned intact, then we are getting
            // a crisscrossed message.
            if (rspicoms.KEY != reqicoms.KEY)
            {
                throw new CmKeyMismatchException();
            }

            return(rspicoms);
        }          // CmMethod()