Ejemplo n.º 1
0
        /// <summary>
        /// Send SOAP with the following format
        /// </summary>
        /// <param name="body"></param>
        /// <param name="webServiceUri"></param>
        /// <param name="soapAction"></param>
        /// <param name="header"></param>
        /// <param name="host"></param>
        /// <param name="httpMethod"></param>
        /// <param name="contentType"></param>
        /// <param name="httpVersion"></param>
        /// <param name="throwExceptionIfHttpException"></param>
        /// <remarks>
        /// 
        /// POST (@webServiceUri) HTTP/(@version)
        /// Host: (@webServiceUri.Host or @host)
        /// Content-Type: (@contentType)
        /// Content-Length: length
        /// SOAPAction: "(@soapAction)"
        /// 
        /// &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
        /// &lt;soap:Envelope xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
        /// &lt;soap:Header&gt;
        /// (@header)
        /// &lt;/soap:Header&gt;
        /// &lt;soap:Body&gt;
        /// (@body)
        /// &lt;/soap:Body&gt;
        /// &lt;/soap:Envelope&gt;
        /// 
        /// </remarks>
        /// <returns></returns>
        public static SoapResponse Send(SoapRequest soapRequest, bool throwExceptionIfHttpException = true)
        {
            var request = soapRequest.PreparHttpWebRequest(); // this just prepare the HttpHeaders
            var buffer = soapRequest.HttpBytes; // get the byte[] for Soap message

            var requestStream = request.GetRequestStream();
            requestStream.Write(buffer, 0, buffer.Length);


            var response = (HttpWebResponse)request.GetResponse();

            // response
            var result = new SoapResponse(response);

            if (throwExceptionIfHttpException && result.HttpStatusCodeNumber >= 400)
            {
                throw new WhiteMarsException(string.Format("Http Exception: {0} - {1}", result.HttpStatusCodeNumber, result.HttpStatusDescription));
            }

            return result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send SOAP with the following format
        /// </summary>
        /// <param name="body"></param>
        /// <param name="webServiceUri"></param>
        /// <param name="soapAction"></param>
        /// <param name="header"></param>
        /// <param name="host"></param>
        /// <param name="httpMethod"></param>
        /// <param name="contentType"></param>
        /// <param name="httpVersion"></param>
        /// <param name="throwExceptionIfHttpException"></param>
        /// <remarks>
        ///
        /// POST (@webServiceUri) HTTP/(@version)
        /// Host: (@webServiceUri.Host or @host)
        /// Content-Type: (@contentType)
        /// Content-Length: length
        /// SOAPAction: "(@soapAction)"
        ///
        /// &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
        /// &lt;soap:Envelope xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
        /// &lt;soap:Header&gt;
        /// (@header)
        /// &lt;/soap:Header&gt;
        /// &lt;soap:Body&gt;
        /// (@body)
        /// &lt;/soap:Body&gt;
        /// &lt;/soap:Envelope&gt;
        ///
        /// </remarks>
        /// <returns></returns>
        public static SoapResponse Send(SoapRequest soapRequest, bool throwExceptionIfHttpException = true)
        {
            var request = soapRequest.PreparHttpWebRequest(); // this just prepare the HttpHeaders
            var buffer  = soapRequest.HttpBytes;              // get the byte[] for Soap message

            var requestStream = request.GetRequestStream();

            requestStream.Write(buffer, 0, buffer.Length);


            var response = (HttpWebResponse)request.GetResponse();

            // response
            var result = new SoapResponse(response);

            if (throwExceptionIfHttpException && result.HttpStatusCodeNumber >= 400)
            {
                throw new WhiteMarsException(string.Format("Http Exception: {0} - {1}", result.HttpStatusCodeNumber, result.HttpStatusDescription));
            }

            return(result);
        }