Pau*_*ann 6 c# entity-framework wcf-data-services
我目前正在使用带有Entity Framework的WCF数据服务(以及ADO.Net数据服务),并且在执行POST时出现以下错误(省略/更改了一些不相关的信息):
<?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>
Run Code Online (Sandbox Code Playgroud)
在网上浏览一下,我似乎无法找到有关此消息的大量信息,因此调试它有点困难.这可能是因为我发布的一个属性是一个很大的base64字符串(如果我不发布它,它可以正常工作).我试过设置maxRequestLength如下:
<httpRuntime maxRequestLength="102400" />
Run Code Online (Sandbox Code Playgroud)
但它似乎没有帮助.虽然我会继续解决这个问题,但我想我会在这里做一个快速的帖子,看看是否有人知道可能会有所帮助的事情.
我的WCF数据服务类如下所示:
public class MyWcfDataServices: DataService<ContextName>
{
public static void InitializeService(DataServiceConfiguration config)
{
// set entity access rules etc
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
编辑:我似乎没有得到这个.这是我到目前为止所尝试的内容.
在服务器端,我设置了以下绑定:
<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>
Run Code Online (Sandbox Code Playgroud)
希望该maxItemsInObjectGraph属性是解决方案.这些绑定看起来是否正确?我错过了一些可以让我将更多数据发布到服务器的属性吗?我是否还需要在客户端上配置此服务行为?
Pau*_*ann 18
好的,这就是我为解决这个问题所做的工作.首先,我通过在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>
Run Code Online (Sandbox Code Playgroud)
这给了我更多关于这些问题的信息,特别是在我的情况下,最大请求长度仍然是65536,这表明我的绑定没有被提取.这可以归结为两件事,首先name我的service配置部分不正确 - 它需要包含命名空间信息.我最终得到了这个(我不得不把它放在客户端的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>
Run Code Online (Sandbox Code Playgroud)
最后,我必须将我的.svc文件的标记中的工厂从模板生成的System.Data.Services程序集更改为Microsoft的ODATA程序集(其中也包含System.Data.Services名称空间)System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
我现在的头发比起初时少,但这是你付出的代价.
我遇到这个问题是因为我的 DataContract 中的一些 DataMembers 只有 get 方法。例如
[DataMember]
public Name { get; }
Run Code Online (Sandbox Code Playgroud)
会导致这个错误。要解决您应该拥有的问题
[DataMember]
public Name {get; set;}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18186 次 |
| 最近记录: |