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 8084413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:47:27+00:00 2026-06-05T17:47:27+00:00

I am new to WCF so I think this is pretty basic. I have

  • 0

I am new to WCF so I think this is pretty basic. I have a simple method that a single “order” object is returned. It works just fine when using the default XML, however, when I apply the

ResponseFormat = WebMessageFormat.Json

attribute, it fails to return JSON. The code successfully executes and hits the return line but then the method is immediately called again and then finally a third time before the browser returns an error stating the connection to localhost has been interrupted.

When I remove the ResponseFormat = WebMessageFormat.Json, the method is called and XML is returned just fine. Not sure I am missing for the JSON.

IProductSales.cs

namespace ProductsSalesService
{
    [ServiceContract(Name = "ProductsSales")]
    public interface IProductsSales
    {

        [OperationContract]
        [WebGet(UriTemplate = "Orders/{orderID}", ResponseFormat = WebMessageFormat.Json)]
        [Description("Returns the details of an order")]
        SalesOrderHeader GetOrder(string orderID);

    }
}

ProductSales

public SalesOrderHeader GetOrder(string orderID)
{
    SalesOrderHeader header = null;

    try
    {
        int id = Convert.ToInt32(orderID);
        AdventureWorksEntities database = new AdventureWorksEntities();

            header = (from order in database.SalesOrderHeaders
                      where order.SalesOrderID == id
                      select order).FirstOrDefault();

    }
    catch
    {
        throw new WebFaultException(HttpStatusCode.BadRequest);
    }

    return header;
}

I am working through an sample in a WCF book so they had me build a small console application to be the host, so this is the app.config file I have for the host client.

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="AdventureWorksEntities" connectionString="metadata=res://*/ProductsSalesModel.csdl|res://*/ProductsSalesModel.ssdl|res://*/ProductsSalesModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=BINGBONG;Initial Catalog=AdventureWorks;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.serviceModel>
    <services>
      <service name="ProductsSalesService.ProductsSales">
        <endpoint address="http://localhost:8000/Sales" binding="webHttpBinding"
          bindingConfiguration="" name="ProductsSalesService.ProductsSales"
          contract="ProductsSalesService.IProductsSales" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

Finally, this is just the host client code.

public class Program
    {
        static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(ProductsSalesService.ProductsSales));
            host.Open();
            Console.WriteLine("Service running");
            Console.WriteLine("Press ENTER to stop the service");
            Console.ReadLine();
            host.Close();
        }
    }

So when I go to http://localhost:8000/Sales/Orders/43659 to pull up my order it hits three times and the page cancels in Chrome with the following error:

This webpage is not available The connection to localhost was
interrupted. Here are some suggestions: Reload this webpage later.
Check your Internet connection. Restart any router, modem, or other
network devices you may be using. Add Google Chrome as a permitted
program in your firewall’s or antivirus software’s settings. If it is
already a permitted program, try deleting it from the list of
permitted programs and adding it again. If you use a proxy server,
check your proxy settings or contact your network administrator to
make sure the proxy server is working. If you don’t believe you should
be using a proxy server, adjust your proxy settings: Go to the wrench
menu > Settings > Show advanced settings… > Change proxy settings…

LAN Settings and deselect the “Use a proxy server for your LAN” checkbox. Error 101 (net::ERR_CONNECTION_RESET): The connection was
reset.

If I remove the WebMessageFormat.Json everything works fine!

Thanks for any assistance!

  • 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-05T17:47:29+00:00Added an answer on June 5, 2026 at 5:47 pm

    For starters try WCF tracing/logging to see if it sheds any light on things.

    Put this in your server’s config file (somewhere within the <configuration> element):-

    <system.diagnostics>
     <sources>
      <source name="System.ServiceModel" switchValue="Error" propagateActivity="true">
        <listeners>
          <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\Temp\server.svclog"/>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messages"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="C:\Temp\server_messages.svclog" />
        </listeners>
      </source>
     </sources>
    </system.diagnostics>
    

    And put this inside the <system.serviceModel> element:-

    <diagnostics>
      <messageLogging
           logEntireMessage="true"
           logMalformedMessages="false"
           logMessagesAtServiceLevel="true"
           logMessagesAtTransportLevel="false"
           maxMessagesToLog="3000"
           maxSizeOfMessageToLog="2000"/>
    </diagnostics>
    

    Try hitting your service again and examine the .svclog files that this (hopefully) generates for clues. The files will open in a “Service Trace Viewer” tool – if not it can be downloaded from MS (part of the Win SDK I think).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to WCF in general. What little experience I have comes
I have a quite simple WCF service method which returns an IQueryable, just for
I created WCF service that returns a custom object called XmlElementTreeNode. This is what
I have a WCF service that can return a stream via a WebGet. This
I apologise if this seems a little basic, but I'm new to WCF -
I need to build a process that listen in WCF for new tasks. (Async)
I have this code: if (archivoBinario != null) { MemoryStream ms = new MemoryStream(archivoBinario);
I have a Windows WCF serivce and Web client. My service has one method
I'm a bit new to WCF and I don't think I completely understand what
I have a WCF service (not RIA) that I access from Silverlight. The application

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.