用程序调用WCF

来源:互联网 发布:股票交易软件制作公司 编辑:程序博客网 时间:2024/05/21 04:19
//上传实体信息var job = new JobInfo();job.Name = "tset";var jobStr = JsonConvert.SerializeObject(job);string postcontent = "{\"jobInfo\":" + jobStr + ",\"userkey\":\"123123\"}";byte[] postData = System.Text.Encoding.UTF8.GetBytes(postcontent);var request = HttpWebRequest.Create("http://localhost:11483/MyService.svc/UploadJob");request.Method = "Post";request.ContentType = "application/json";request.ContentLength = postData.Length;var requestStream = request.GetRequestStream();requestStream.Write(postData, 0, postData.Length); var reader = new StreamReader(request.GetResponse().GetResponseStream());var result = reader.ReadToEnd();
//图片上传测试var postData = Encoding.Default.GetBytes("{\"userkey\":\"0d080db5-4c66-4a90-afff-d7af7d8816b0\",\"extension\":\".jpg    \"}");var request = HttpWebRequest.Create("http://localhost:11483/MyService.svc/UploadImg");var fileBytes = File.ReadAllBytes(@"D:\1.png");request.Method = "Post";request.ContentType = "application/octet-stream";request.ContentLength = postData.Length + fileBytes.Length;var requestStream = request.GetRequestStream();requestStream.Write(postData, 0, postData.Length);requestStream.Write(fileBytes, 0, fileBytes.Length);var reader = new StreamReader(request.GetResponse().GetResponseStream());var result = reader.ReadToEnd();
0 0