不向Web服务发送数据

这是我发送数据的代码。 有一个字符串strJson我想将字符串数据发送到我已集成的服务引用。

ServiceReference3.Service1Client client = new ServiceReference3.Service1Client(); client.GetOrderAsync(strJson); 

它抛出以下exception:类型的exception

System.ServiceModel.ni.dll中发生’System.ServiceModel.CommunicationException’但未在用户代码中处理

exception地点:它打开reference.cs,并在此代码中抛出exception。

System.ServiceModel.ni.dll中出现“System.ServiceModel.FaultException”类型的exception,但未在用户代码中处理

 public bool EndGetOrder(System.IAsyncResult result) { object[] _args = new object[0]; bool _result=((bool)(base.EndInvoke("GetOrder", _args, result)));//At this line exception occurs return _result; } 

试试这个

 var c = new HttpClient { BaseAddress = new Uri("Your URL") }; c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var json = "Your json string" var req = new HttpRequestMessage(HttpMethod.Post, "Your Method name in URI Template") { Content = new StringContent(json, Encoding.UTF8, "application/json") }; c.SendAsync(req).ContinueWith(respTask => { var response = respTask.Result.Content.ReadAsStringAsync(); Console.WriteLine("Response: {0}", respTask.Result); }); }