string postData = " <UserEntity xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" + "<UserID>254</UserID></UserEntity>";
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); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)