You must Sign In to post a response.
  • Category: WCF

    Wcf with JSON input parameter

    Hi Folks,

    Iam new to .net ,Iam a fresher .I have one challenging task.Please help me out with this ,as it is very urgent.I should develop WCF service which has JSON Input parameter as below


    i.e {ID : "123", Ph : "111111"}

    In my WCF i should receive these two input and pass it to Oracle Stored Procedure as Text and pass it to storedprocedure.Please can anyone help me out with this ..Please send me its very urgent


    Note: Since iam fresher.Iam struggling with this task.


    Thanks,
    Sam
  • #766138
    To handle the WCF in Json is very simple. You have to take care the following in your application.

    In the WCF interface specify the Request and Response format.

    [OperationContract]
    [WebInvoke(UriTemplate = "/Login",
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json, Method = "POST")]
    Login_Response Login(Login_Request Login_RequestP);


    You can all the WCF service as follows as REST Call.

    HttpWebRequest TheRequestL = (HttpWebRequest)WebRequest.Create("URL");
    TheRequestL.ContentType = "application/json";
    TheRequestL.ContentLength = zInputJsonDataP.Length;

    TheRequestL.Method = "POST";
    TheRequestL.AllowAutoRedirect = false;

    Stream aRequestStreamL = TheRequestL.GetRequestStream();
    byte[] postBytes = System.Text.Encoding.ASCII.GetBytes(zInputDataP);
    aRequestStreamL.Write(postBytes, 0, postBytes.Length);
    aRequestStreamL.Close();

    HttpWebResponse aResponseL = (HttpWebResponse)TheRequestL.GetResponse();
    string zVersionL = aResponseL.ProtocolVersion.ToString();
    StreamReader aStreamReaderL = new StreamReader(aResponseL.GetResponseStream());

    StringBuilder aHttpCallXmlOutL = new StringBuilder();
    string zTempL;
    while ((zTempL = aStreamReaderL.ReadLine()) != null)
    {
    aHttpCallXmlOutL.Append(zTempL);
    }

    aStreamReaderL.Close();
    zOutputDataP = aHttpCallXmlOutL.ToString();

    By Nathan
    Direction is important than speed


Sign In to post your comments