我可以通过Wcf Post Method将数据从webisite发送到数据库 服务电话。数据保存到数据库但我无法接收 信息。它返回null值。
byte[] data;
Stream stream ;
DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(string));
LoginDetails student = new LoginDetails { Name = "Mohanraj", LoginType = 1,Password="qssaz",Mobile="86945",imei="asdfdasasaa",LoginID="ab@b.com" };
WebClient Proxy1 = new WebClient();
Proxy1.Headers["Content-type"] = "application/json";
MemoryStream ms = new MemoryStream();
DataContractJsonSerializer serializerToUplaod = new DataContractJsonSerializer(typeof(LoginDetails));
serializerToUplaod.WriteObject(ms, student);
data = Proxy1.UploadData("http://songapp.ccpvl.com/Services/BasicService.svc/MemberRegistration", "POST", ms.ToArray());
stream = new MemoryStream(data);
obj = new DataContractJsonSerializer(typeof(LoginDetails));
var resultStudent = obj.ReadObject(stream) as LoginDetails;
Console.WriteLine(resultStudent.LoginID+" " + resultStudent.Name);
Console.ReadKey(true);
答案 0 :(得分:0)
在此代码中工作.......................
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost/Services/BasicService.svc/MemberRegistration");
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/json";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
var NAME= "adss";
var LoginTypes = 1;
var Passwords = "asasaytsasasa"; var MobileNo = "23456fd587"; var imeino = "e35tfgg5"; var LoginIDs = "abfcsdskghj@google.com";
string jSonData = "{" + "\"Name\":\"" + NAME + "\"," + "\"LoginType\":\"" + LoginTypes + "\"," + "\"Password\":\"" + Passwords + "\"," + "\"Mobile\":\"" + MobileNo + "\"," + "\"imei\":\"" + imeino + "\"," + "\"LoginID\":\"" + LoginIDs + "\"}";
streamWriter.Write(jSonData);
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}
}
catch
{
}