Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to pass the parameter of URL, URL_ServiceName , URL_MethodName when calling the method send() from TAService Class.Currently passing postData only.
PLease help me.


Calling the Method :
string postData = " <UserEntity xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" + "<UserID>254</UserID></UserEntity>";



TAService.send(this, postData);
///////////////////////////////
The Method is:
C#
public class TAService
    {

        private static String URL = "http://172.19.18.126/TAExcelApps";
        private static string URL_ServiceName = "LoginService";
        private static string URL_MethodName = "GetUserAuthenticate";
        private static String SERVICE_URL = URL + "/" + URL_ServiceName + "/" + URL_MethodName;

        private static HttpWebRequest request;


        private static HttpWebRequest Request
        {
            
            get
            {
               if (request == null)
                {
                    request = (HttpWebRequest)WebRequest.Create(SERVICE_URL);
                    request.ContentType = "application/xml"; 
                    request.Method = "POST";
                }
                return request;
            }
        }

        public static void send(IService service, String postData)
        {
            try
            {
                request = Request;
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                request.ContentLength = byteArray.Length;

                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }

                using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse)
                {
                    Stream ResponseStream = null;
                    ResponseStream = httpResponse.GetResponseStream();
                    int responseCode = (int)httpResponse.StatusCode;
                    service.onSuccess((new StreamReader(ResponseStream)).ReadToEnd());
                }
            }
            catch (WebException Ex)
            {
                if (Ex.Status == WebExceptionStatus.ProtocolError)
                {
                    int StatusCode = (int)((HttpWebResponse)Ex.Response).StatusCode;
                    Stream ResponseStream = null;
                    ResponseStream = ((HttpWebResponse)Ex.Response).GetResponseStream();
                    service.onError(new Exception((new StreamReader(ResponseStream)).ReadToEnd()));

                }

            }


            catch (Exception exception)
            {
                service.onError(exception);
            }
            
        }
    }
Posted
Updated 9-Sep-13 23:24pm
v2
Comments
Joezer BH 10-Sep-13 5:36am    
What have you tried?
What problem are you getting?
connect2manas 10-Sep-13 7:19am    
i have not done
please give some idea

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