2013-01-21 64 views
3

我正在使用Entity Framework使用WCF数据服务(以及ADO.Net数据服务),并在执行POST时收到以下错误(省略/改变了一些无关紧要的信息):远程主机强制关闭现有连接 - WCF数据服务错误

<?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> 

有环顾四周网上,我似乎无法找到有关此消息,以便调试它是一个有点困难多的信息。这很可能是因为我发布的一个属性是一个大型的base64字符串(如果我不发布这个,它可以正常工作)。我已经尝试设置maxRequestLength以下几点:

<httpRuntime maxRequestLength="102400" /> 

但它似乎并没有帮助。虽然我会继续努力完成这个任务,但我认为我会在这里做一个快速发布,看看是否有人知道可能有帮助的事情。

我的WCF数据服务类看起来是这样的:

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

感谢

编辑:我似乎没有要与此Anywhere入门。这是迄今为止我尝试过的。

在服务器端我已经设置以下绑定:

<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> 

希望的maxItemsInObjectGraph属性将是解决办法。这些绑定看起来是否正确?我是否缺少一些可让我将更多数据发布到服务器的属性?我是否也需要在客户端上配置此服务行为?

回答

13

好的,这是我做了什么来解决这个问题。首先,我能够通过添加以下到我的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> 

这给了我有关的问题的更多的信息,特别是在我的情况下,最大请求长度仍然,这表示我的绑定未被拾取。这可以归结为两件事情,首先我的service配置的name部分不正确 - 它需要包含名称空间信息。我结束了这个(我不得不把这个客户端的web.config太):最后

<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> 

,我在从模板我的.svc文件的标记来改变工厂产生System.Data.Services装配微软ODATA程序集(其中也包含System.Data.Services命名空间)System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

现在我的头发比我刚开始的时候少了,但是这是你付出的代价。

+0

你应该得到两个upvotes,一个用于答案,一个用于“少发”的笑话。唉,我只能赞成一次。 –

1

我得到这个问题,因为我的DataContract中的一些DataMember只有get方法。例如

[DataMember] 
public Name { get; } 

将导致此错误。要解决这个问题,你应该有

[DataMember] 
public Name {get; set;} 
相关问题