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:
Hi,

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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ecprovws.bcs.com/">
   <soapenv:Header>
   <ecProvAuthHeader0><clientId>SomeClientId</clientId><clientKey>SomeClientKey</clientKey></ecProvAuthHeader0></soapenv:Header>
   <soapenv:Body>
      <ws:getConferences>
         <!--Optional:-->
         <!--type: dateTime-->
         <startDate>2014-01-01</startDate>
         <!--Optional:-->
         <!--type: dateTime-->
         <endDate>2016-02-28</endDate>
         <!--Optional:-->
         <!--type: string-->
         <organizationAlias>SomeCompanyAlias</organizationAlias>
      </ws:getConferences>
   </soapenv:Body>
</soapenv:Envelope>


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)
    {
        CallWebService();
    }

    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.
        asyncResult.AsyncWaitHandle.WaitOne();

        // 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=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/1999/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema""><SOAP-ENV:Body><HelloWorld xmlns=""http://tempuri.org/"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><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=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ws=""http://ws.ecprovws.bcs.com/""><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())
        {
            soapEnvelopeXml.Save(stream);
        }
    }


Please help me.
Posted
Comments
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 = "http://68.64.91.15:8080/EcProvWs/EcProvWs?wsdl";
        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);
        requestStream.Close();

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

        HttpContext.Current.Response.Write(backstr);
        sr.Close();
        res.Close();
   

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