Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:37:49+00:00 2026-06-02T14:37:49+00:00

How can I test WCF JSON services. I want to create something like unit

  • 0

How can I test WCF JSON services. I want to create something like unit tests for this services. Is there any tutorial for something like this? I would b most interested to write the JSON object myself like
{somedata:abc,foo:boo}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:37:50+00:00Added an answer on June 2, 2026 at 2:37 pm

    Here is a link that might get you started.

    http://www.entechsolutions.com/wcf-web-service-for-soap-json-and-xml-with-unit-tests

    “-create a dynamic class that matches JSON datastructure
    -Serialize it to JSON
    -Send json to web service
    -Deserilize response to a dynamic object
    -Make sure that response has value that I expected”

    POST

    [Test]
    public void Add_WhenMethodPost_And_ValidApiKey_ReturnsSum()
    {
    var addRequest = new
    {
        Value1 = 5,
        Value2 = 11,
        ApiKey = Const.ValidApiKey
    };
    
    var url = string.Format("{0}/json/add", Const.WebServiceUrl);
    var request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "POST";
    request.ContentType = "application/json; charset=utf-8";
    
    var jsSerializer = new JavaScriptSerializer();
    var jsonAddRequest = jsSerializer.Serialize(addRequest);
    
    var writer = new StreamWriter(request.GetRequestStream());
    writer.Write(jsonAddRequest);
    writer.Close();
    
    var httpWebResponse = (HttpWebResponse)request.GetResponse();
    
    string jsonString;
    using (var sr = new StreamReader(httpWebResponse.GetResponseStream()))
    {
        jsonString = sr.ReadToEnd();
    }
    
    var jsonAddResponse = jsSerializer.Deserialize<dynamic>(jsonString);
    
    Assert.AreEqual(16, jsonAddResponse["Sum"]);
    }
    

    GET

    [Test]
    public void Add_WhenMethodGet_And_ValidApiKey_ReturnsSum()
    {
     var url = string.Format("{0}/json/add?value1={1}&amp;value2={2}&amp;apiKey={3}", Const.WebServiceUrl, 5, 11,
                             Const.ValidApiKey);
     var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
     httpWebRequest.Method = WebRequestMethods.Http.Get;
     httpWebRequest.Accept = "application/json";
    
     string jsonString;
     var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    
     using (var sr = new StreamReader(httpWebResponse.GetResponseStream()))
     {
         jsonString = sr.ReadToEnd();
     }
    
     var jsSerializer = new JavaScriptSerializer();
     var jsonAddResponse = jsSerializer.Deserialize<dynamic>(jsonString);
    
     Assert.AreEqual(16, jsonAddResponse["Sum"]);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like it should be easier to test my WCF Services. Is there
Is there a way I can test if there are any other activities in
I am wondering is there any way we can test the font size/color of
How can you test a WCF Service Application like you could do with ASP.NET
This is my first attempt to use WCF so there may be something fundamentally
I'm trying to write some code to help unit test WCF services. These services
The MSDN docs state that I can find the WCF Test Client in: C:\Program
Is there a page similar to JSbin where I can test HTML and CSS
Can you test touchEvent on Adobe Device Cental, google it can't find any information.
Im getting confused with WCF, can someone clarify this for me please. According to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.