3

Here's my code for sending the data. There is a string strJson i want to send the string data to the service reference i have integrated.

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

It throws Following Exception:An exception of type

'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.ni.dll but was not handled in user code

Exception place:It opens reference.cs and in that at this code it throws following exception.

An exception of type 'System.ServiceModel.FaultException' occurred in System.ServiceModel.ni.dll but was not handled in user code

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;

 }
Mihir
  • 273
  • 2
  • 13

1 Answers1

0

Try this

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);
});
}
Rocky Balboa
  • 922
  • 10
  • 23