Follow Fantora on Twitter
Fantora Word of Classified Ads and Community Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

how to Call web service through HTTP

Options
ca4nul
Posted: Friday, February 03, 2012 9:29:50 AM
Rank: Advanced Member
Groups: Member

Joined: 11/9/2007
Posts: 560
Points: 1,011
Location: GB

how to Call web service through HTTP

Hi,

I am writing a middleware web service which will communicate with the host's web service through HTTP GET/POST (not SOAP).

Web App <-----> Middleware Web Service <--------> Host Web Service

When I write a different web application to test the communication to Host Web Service, its working perfectly. (Test Web App <-------> Host Web Service). I use the following method here.

Code:
private XmlDocument SendHTTPRequest(string url, XmlDocument xReqDoc)
        {
            log.Debug("Inside Method");
            //Declare XMLResponse document
            XmlDocument XMLResponse = null;

            //Declare an HTTP-specific implementation of the WebRequest class.
            HttpWebRequest objHttpWebRequest;

            //Declare an HTTP-specific implementation of the WebResponse class
            HttpWebResponse objHttpWebResponse = null;

            //Declare a generic view of a sequence of bytes
            Stream objRequestStream = null;
            Stream objResponseStream = null;

            //Declare XMLReader
            XmlTextReader objXMLReader;

            //Creates an HttpWebRequest for the specified URL.
            log.Debug("Creates an HttpWebRequest for the specified URL.");
            objHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);

            try
            {
                //---------- Start HttpRequest

                //Set HttpWebRequest properties
                log.Debug("Set HttpWebRequest properties");
                byte[] bytes;
                bytes = System.Text.Encoding.ASCII.GetBytes(xReqDoc.InnerXml);
                objHttpWebRequest.Method = "POST";
                objHttpWebRequest.ContentLength = bytes.Length;
                objHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";

                //Get Stream object
                log.Debug("Get Stream object ");
                objRequestStream = objHttpWebRequest.GetRequestStream();

                //Writes a sequence of bytes to the current stream
                log.Debug("Writes a sequence of bytes to the current stream");
                objRequestStream.Write(bytes, 0, bytes.Length);

                //Close stream
                log.Debug("Close stream");
                objRequestStream.Close();

                //---------- End HttpRequest

                //Sends the HttpWebRequest, and waits for a response.
                log.Debug("Sends the HttpWebRequest, and waits for a response.");
                objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();

                //---------- Start HttpResponse
                if (objHttpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    log.Debug("Start HttpResponse");
                    //Get response stream
                    objResponseStream = objHttpWebResponse.GetResponseStream();

                    //Load response stream into XMLReader
                    log.Debug("Load response stream into XMLReader");
                    objXMLReader = new XmlTextReader(objResponseStream);

                    //Declare XMLDocument
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load(objXMLReader);

                    //Set XMLResponse object returned from XMLReader
                    XMLResponse = xmldoc;

                    //Close XMLReader
                    objXMLReader.Close();
                }

                //Close HttpWebResponse
                log.Debug("Close HttpWebResponse");
                objHttpWebResponse.Close();
            }
            catch (WebException we)
            {
                //TODO: Add custom exception handling
                log.Error(we.Message);
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.Message);
                log.Error(ex.Message);
            }
            finally
            {
                //Close connections
                if (objRequestStream != null)
                    objRequestStream.Close();
                if (objRequestStream != null)
                {
                    objResponseStream.Close();
                }
                if (objHttpWebResponse != null)
                {
                    objHttpWebResponse.Close();
                }

                //Release objects
                objXMLReader = null;
                objRequestStream = null;
                objResponseStream = null;
                objHttpWebResponse = null;
                objHttpWebRequest = null;
            }

            //Return
            return XMLResponse;
        }


But, when I add exactly same method in a class library (DLL) and use it from the actual Middleware Web Service, its giving Internal Server Error (500). The error is thrown after the following line

Code:
objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();


Both these Test Web App & Middleware Service are hosted in the same IIS. Could anyone give a hand to solve this?

Thanks
hightech
Posted: Thursday, February 16, 2012 11:06:28 PM
Rank: Advanced Member
Groups: Member

Joined: 9/6/2008
Posts: 227
Points: 487
Location: US
Users browsing this topic
Guest

 Related
Ultimate Regular Expression Library
blue Dots apearing for spaces in the pages
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding
Commerce server 2009 Basket Only Extension
run CS 2007 code on 2009 R2. Where is Microsoft.CommerceServer.Runtime
Error in Unpacking Data warehouse : Cannot connect to Analysis Services version '10.0.4000.0'
Is it possible to do CatalogSearch without any sort property?
using named Instance of sql server in Commerce Server 2009 Datawarehouse
how to Call web service through HTTP
The module 'CommerceProfileModule' depends on the site resource 'Biz Data Service' which does not exist in the Commerce Server a
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Fantora Blog | Discount Shop UK | Discount Shop USA | Discount Shop Canada | Discount Boutique France | Discount Shop Deutschland | Discount Shop Italia | Descuento Shop España

Free Classified ads, Webmaster Forum & Technology Reviews | Fantora Free Classified Ads | Buy & Sell Electronics, Mobile phones & Accessories | fantora Forums Community | Buy & Sell DVD, Games and Consols | Free eBooks & Softwares | SEO & Affiliate Marketing Discussion | Programming Language Forum (.NET, ASP, PHP, SQL) | Free Classified Ads | General Stuff (Movies, Chat, Comics) | Free Online English Movies & Reviews | Free Online Hindi Movies & Reviews | Australia & New Zealand Immigration Forum | Europe immigration forum | Canada Immigration Forum | Ireland Immigration Forum | US Immigration Forum | United Kingdom Immigration Forum

Main Forum RSS : RSS

Powered by: YAF.NET
Copyright © AI Logica All rights reserved.
This page was generated in 0.709 seconds.