An existing connection was forcibly closed by the remote host - WCF data service error

I am currently using WCF Data Services (well, ADO.Net Data Services) with Entity Framework and am getting the following error when doing POST (some irrelevant information missing / changed):

<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-GB">The URI 'http://localhost:56568/MyWcfDataServices.svc/EntitySetName(pk_id)' is not valid for POST operation. For POST operations, the URI must refer to a service operation or an entity set.</m:message></m:error>

      

Looking around the internet I can't find much information about this post, so debugging is a bit tricky. This is probably because one of the attributes I'm posting is a big base64 string (it works fine if I don't post this). I tried to set maxRequestLength

to the following:

<httpRuntime maxRequestLength="102400" />

      

But it didn't seem to help. While I will continue working on this, I thought I'd make a quick post here to see if anyone knows anything that might help.

My WCF Data Service class looks like this:

public class MyWcfDataServices: DataService<ContextName>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        // set entity access rules etc
    }
}

      

thank

EDIT . I can't seem to do anything about it. Here is what I have tried so far.

On the server side, I have set the following bindings:

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
                             minFreeMemoryPercentageToActivateService="0" />
  <services>
    <service name="MyWcfDataServices" 
             behaviorConfiguration="myBehaviorConfig">
      <endpoint address=""
                binding="webHttpBinding"
                bindingConfiguration=""
                contract="System.Data.Services.IRequestHandler" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="myBehaviorConfig">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

      

Hopefully the attribute maxItemsInObjectGraph

will be a solution. Do these bindings look right? Am I missing some attribute that will allow me to POST more data to the server? Do I also need to customize this service behavior on the client?

+3


source to share


2 answers


OK, here's what I did to fix this issue. I first enabled tracing on the server by adding the following to my web.config:

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

      

This gave me a lot more information about the problems, especially in my case the maximum request length was 65536 which indicated that my bindings were not hoisted. That was down to two things, at first part of name

my configuration service

was wrong - it needed to include namespace information. I ended up with this (I had to put this in the client's web.config too):



<services>
  <service name="Solution.Project.MyWcfDataServices">
    <endpoint address=""
              binding="webHttpBinding"
              bindingConfiguration="webHttpConfig"
              contract="System.Data.Services.IRequestHandler" />
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="webHttpConfig" 
              allowCookies="true"
              maxReceivedMessageSize="20000000"
              maxBufferSize="20000000"
              maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32"
                    maxArrayLength="200000000"
                    maxStringContentLength="200000000" />
    </binding>
  </webHttpBinding>
</bindings>

      

Finally, I had to change the factory in my .svc file markup from a template generated assembly System.Data.Services

to a Microsoft ODATA assembly (which also contains the System.Data.Services namespaces) System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

.

I have less hair than when I started, but what is the price you pay I guess.

+13


source


I was getting this problem because some of the DataMembers in my DataContract were only getting a method. for example

[DataMember]
public Name { get; } 

      



will result in this error. To fix the problem, you must have

[DataMember]
public Name {get; set;}

      

+1


source







All Articles