예제 #1
0
        /// <summary>
        /// Send an Http request to an endpoint and waits for a response.
        /// </summary>
        /// <param name="soapMessage">A byte array containing the soap message to be sent.</param>
        /// <param name="remoteEndpoint">A sting containing the name of a remote listening endpoint.</param>
        /// <returns>
        /// A WsMessage containing a soap response to the request. This array will be null for OneWay request.
        /// </returns>
        public WsMessage SendRequest(WsMessage request, Uri remoteEndpoint)
        {
            WsMessage response = new WsMessage(new WsWsaHeader(), null, WsPrefix.None);

            HttpTransportBindingElement httpClient = new HttpTransportBindingElement(new HttpTransportBindingConfig(remoteEndpoint));
            ClientBindingContext ctx = new ClientBindingContext(m_version);

            ctx.ReceiveTimeout = new TimeSpan(0, 0, 0, 0, ReceiveTimeout);
            ctx.OpenTimeout    = new TimeSpan(0, 0, 0, 0, RequestTimeout);
            ctx.SendTimeout    = new TimeSpan(0, 0, 0, 0, SendTimeout);

            httpClient.EndpointAddress = remoteEndpoint;

            Stream stream = null;

            try
            {
                httpClient.Open(ref stream, ctx);

                httpClient.ProcessOutputMessage(ref request, ctx);

                ctx.BindingProperties.Clear();

                httpClient.ProcessInputMessage(ref response, ctx);

                ctx.BindingProperties.Clear();

                if(response.Body is byte[])
                {
                    response.Reader = WsSoapMessageParser.ParseSoapMessage((byte[])response.Body, ref response.Header, m_version);
                }
            }
            finally
            {
                httpClient.Close(stream, ctx);
            }

            return response;
        }
예제 #2
0
        public void SendRequestOneWay(WsMessage request, Uri remoteEndpoint)
        {
            WsMessage response = new WsMessage(new WsWsaHeader(), null, WsPrefix.None);

            HttpTransportBindingElement httpClient = new HttpTransportBindingElement(new HttpTransportBindingConfig(remoteEndpoint));
            ClientBindingContext ctx = new ClientBindingContext(m_version);
            httpClient.EndpointAddress = remoteEndpoint;

            ctx.OpenTimeout    = new TimeSpan(0, 0, 0, 0, RequestTimeout);
            ctx.SendTimeout    = new TimeSpan(0, 0, 0, 0, SendTimeout);

            Stream stream = null;

            try
            {
                httpClient.Open(ref stream, ctx);
                httpClient.ProcessOutputMessage(ref request, ctx);
            }
            finally
            {
                httpClient.Close(stream, ctx);
            }
        }