Click here to Skip to main content
14,732,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I need to integrate BeaconLive API to my application. In this SOAP API the soap headers are not part of SOAP webservice. We need to pass SOAP header on request.

Below is the sample XML which is the reqeust XML:

<soapenv:Envelope xmlns:soapenv="" xmlns:ws="">
         <!--type: dateTime-->
         <!--type: dateTime-->
         <!--type: string-->

I tested above XML with live credentials in SOAPUI software and I am getting the result for the same.

When I am trying to send this XML to endpoint URL I am not getting any result.
Below is my C# code:
protected void Page_Load(object sender, EventArgs e)

    public static void CallWebService()
        var _url = "someEndPointURL";
        var _action = "";

        XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
        HttpWebRequest webRequest = CreateWebRequest(_url, _action);
        InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

        // begin async call to web request.
        IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

        // suspend this thread until call is complete. You might want to
        // do something usefull here like update your UI.

        // get the response from the completed web request.
        string soapResult;
        using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
            using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                soapResult = rd.ReadToEnd();
            HttpContext.Current.Response.Write (soapResult);

    private static HttpWebRequest CreateWebRequest(string url, string action)
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
        webRequest.Headers.Add("SOAPAction", action);
        webRequest.ContentType = "text/xml;charset=\"utf-8\"";
        webRequest.Accept = "text/xml";
        webRequest.Method = "POST";
        return webRequest;

    private static XmlDocument CreateSoapEnvelope()
        XmlDocument soapEnvelop = new XmlDocument();
        //soapEnvelop.LoadXml(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV="""" xmlns:xsi="""" xmlns:xsd=""""><SOAP-ENV:Body><HelloWorld xmlns="""" SOAP-ENV:encodingStyle=""""><int1 xsi:type=""xsd:integer"">12</int1><int2 xsi:type=""xsd:integer"">32</int2></HelloWorld></SOAP-ENV:Body></SOAP-ENV:Envelope>");
        soapEnvelop.LoadXml(@"<soapenv:Envelope xmlns:soapenv="""" xmlns:ws=""""><soapenv:Header><ecProvAuthHeader0><clientId>SomeClientId</clientId><clientKey>SomeClientKey</clientKey></ecProvAuthHeader0></soapenv:Header><soapenv:Body><ws:getConferences><startDate>2014-01-01</startDate><endDate>2016-02-28</endDate><organizationAlias>SomeCompanyAlial</organizationAlias></ws:getConferences></soapenv:Body></soapenv:Envelope>");
        return soapEnvelop;

    private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        using (Stream stream = webRequest.GetRequestStream())

Please help me.
TheKarateKid 19-Feb-15 11:42am
Please check the Request and response by enabling the tracing on WCF config file and inspecting them with SvcTraceViewer.exe when you are accessing the required endpoint.
It is throwing any fault exception? if yes, you might want to enable the setting to flow the FaultException details to the client.

1 solution

Hi, I got the solution

string xml = @"xml string";
        string url = "";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

        byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);
        req.Method = "POST";
        req.ContentType = "text/xml;charset=utf-8";
        req.ContentLength = requestBytes.Length;
        Stream requestStream = req.GetRequestStream();
        requestStream.Write(requestBytes, 0, requestBytes.Length);

        HttpWebResponse res = (HttpWebResponse)req.GetResponse();
        StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
        string backstr = sr.ReadToEnd();


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900