1

The result of the WCF service causes the browser to be displayed so that "t...

 3 years ago
source link: https://www.codesd.com/item/the-result-of-the-wcf-service-causes-the-browser-to-be-displayed-so-that-the-page-can-not-be-displayed-in-some-cases.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The result of the WCF service causes the browser to be displayed so that "the page can not be displayed" in some cases

advertisements

I am working on a WCF service which returns a record set based on query string parameters (like, starting page, page size), like this:

/{service-url}/?{some-other-parms}&pageindex=0&pagesize=9999&pagecount=1

I recently encountered a scenario where the browser (Chrome, FF, IE9) returns "page cannot be displayed" when I request all records. And it appears to encounter an exception during serialization.

I tried to play around with the parameters and found out if I set &pagesize=1598, the result returns perfectly (as an XML on the browser). If I go beyond that, the error occurs. So it seemed there was an offending data in the record set it returns. However, if I adjust the parameters to actually return only that seemingly offending data, it returns the result perfectly. So I'm now suspecting it is somehow in the serialization process. The app uses DataContract on the record class it returns. But it does not appear to override the serialization process (or nothing I could see it doing). How can I fix this?

I have put a step in the service method to log somewhere the number of records it returns. And on instances where the browser shows "page cannot be displayed", the log is indicating that it returned a non-empty record set. So I'm guessing the serialization is causing the result to be invalid so the browser could not render.


It might be because of the messagesize you receive from your service.

There is two things to do.

Setup diagnostics on you service to see which exceptions are encountered.

in you web.config file:

<system.diagnostics>
  <sources>
    <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
      <listeners>
        <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces.svclog" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>

Or on you httpbindings extend the maxReceivedMessageSize:

<binding name="BasicHttpEndpointBinding" sendTimeout="00:05:00"  receiveTimeout="00:05:00" maxReceivedMessageSize="10485760">


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK