Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Passing parameter in a method.

$
0
0
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 :
 Collapse | Copy Code
  string postData = "<UserEntity xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>"+ "<UserID>254</UserID></UserEntity>";


TAService.send(this, postData);
///////////////////////////////
The Method is:
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);
}

}
}

Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>