By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Pass parameters to java webservice from c#.net

P: 1
Below are 2 ways i tried but m not able to pass parameters to the web service

Expand|Select|Wrap|Line Numbers
  1. <1>
  2. Uri address = new Uri("http://203.88.135.58:8083/JLLSFAServer/SalesForceAutomation/loginVerification");  
  3.  
  4.         // Create the web request  
  5.         HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;  
  6.  
  7.         // Set type to POST  
  8.         request.Method = "POST";
  9.         request.ContentType = "application/x-www-form-urlencoded";  
  10.  
  11.         // Create the data we want to send  
  12.         string appId = "loginName";
  13.         string context = "password";  
  14.  
  15.  
  16.         StringBuilder data = new StringBuilder();
  17.         data.Append("loginName=" + HttpUtility.UrlEncode("E000002028"));
  18.         data.Append("&password=" + HttpUtility.UrlEncode("49505152"));  
  19.         //data.Append("&query=" + HttpUtility.UrlEncode(query));  
  20.  
  21.         // Create a byte array of the data we want to send  
  22.         byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());  
  23.  
  24.         // Set the content length in the request headers  
  25.         request.ContentLength = byteData.Length;  
  26.  
  27.         // Write data  
  28.         Stream postStream = request.GetRequestStream();
  29.             postStream.Write(byteData, 0, byteData.Length);
  30.  
  31.  
  32.         // Get response  
  33.         using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)  
  34.         {  
  35.          // Get the response stream  
  36.          StreamReader reader = new StreamReader(response.GetResponseStream());  
  37.  
  38.          // Console application output  
  39.           string results=reader.ReadToEnd();  
  40.         }  
  41.  
  42.  
  43.  
  44. <2>
  45. WebClient request = new WebClient();
  46.             string data = "E000002028";
  47.             string password = "49505152";
  48.             string postData = "{\"loginName\":\"" + data + "\"" + "&\"password\":\"" + password + "\"}";
  49.             byte[] bytearray = Encoding.UTF8.GetBytes(postData);
  50.  
  51.             request.Headers.Add("Content-Type", "application/json");
  52.  
  53.             string results= request.UploadString("http://203.88.135.58:8083/JLLSFAServer/SalesForceAutomation/loginVerification", "POST", postData);
  54.  
  55.  
  56.  

Its returning 4 which webservice returns when login name is invalid.
Can anyone help me in this??
Is the parameter passing way correct??
Apr 5 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.