locked
multiple Http request in WCF RRS feed

  • Question

  • User-776477372 posted

    By using following method SendingHTTPRequest(), I am sending multiple request 

    foreach (SessionIds sid in Air_E_n_Dst_E)
    {

    if (sid._activecontext == true)

    {  

            SendingHTTPRequest("asdfsd", "sdfdfsdf", "<abcQuery>", "QueryType")

    }
    continue;

    }

    public static String SendingHTTPRequest(String wsap, String session, String query, string queryType)
    {
    System.Net.HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(CommonAppSettings.amd_UrlAddress);
    request.Credentials = CredentialCache.DefaultNetworkCredentials;
    request.Proxy = null;
    request.Method = "POST";
    request.ContentType = "text/xml; charset=utf-8";
    request.Headers.Add("SOAPAction:\"http://testWcfService.com/" + wsap + "/" + queryType + "\"");
    String final_query = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    final_query += "<s:Header>";
    final_query += session;
    final_query += "</s:Header>";
    final_query += "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
    final_query += query;
    final_query += "</s:Body>";
    final_query += "</s:Envelope>";
    byte[] query_byte = Convert(final_query, Encoding.UTF8.GetEncoder());
    request.ContentLength = query_byte.Length;
    Stream request_stream;
    try
    {
    request_stream = request.GetRequestStream();
    }
    catch (Exception e)
    {

    if (e.InnerException != null)
    {
    return e.InnerException.Message;
    }
    return e.Message;
    }

    request_stream.Write(query_byte, 0, query_byte.Length);
    HttpWebResponse response = null;
    try
    {
    response = (HttpWebResponse)request.GetResponse();
    }
    catch (Exception e)
    {


    FieldInfo fi = request.GetType().GetField("_HttpResponse", BindingFlags.NonPublic | BindingFlags.Instance);
    if (fi != null)
    {
    response = (HttpWebResponse)fi.GetValue(request);
    }
    if (response == null)
    {
    request_stream.Close();
    if (e.InnerException != null)
    {
    return e.InnerException.Message;
    }
    return e.Message;
    }
    else
    {

    }
    }
    Stream response_stream = response.GetResponseStream();

    StreamReader sr = new StreamReader(response_stream);
    String result = sr.ReadToEnd();
    sr.Close();
    request_stream.Close();
    response_stream.Close();
    return result;
    }

    Monday, April 22, 2013 6:17 AM

All replies

  • User220959680 posted

    what is the question of discussion?

    Please inform

    Monday, April 22, 2013 6:29 AM