WCF 4 REST 服务的正确配置是什么?
很抱歉发布这个消息,但这让我发疯。我在 VS2010 中的 WCF4 REST 模板中使用路由。我将 maxreceivedmessagesize 属性设置为某个巨大的数字,当我尝试向服务提交 xml 时,它仍然给出 HTTP 状态代码 400。我打开了跟踪,消息告诉我它仍然设置为默认消息大小。这让我认为问题出在我的 web.config 设置方式上的一些细微差别。有人可以快速了解一下并让我知道他们的想法吗?
我一直在研究这个问题,多一双眼睛对我来说会有很大的好处。提前致谢!
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" openTimeout="00:25:00" closeTimeout="00:25:00" sendTimeout="00:25:00" receiveTimeout="00:25:00" maxBufferSize="2147483647">
<readerQuotas maxDepth="64"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="9000000"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" transferMode="Streamed" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<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>
</configuration>
Sorry to post about this, but it's driving me nuts. I am using routes in the WCF4 REST template in VS2010. I set the maxreceivedmessagesize property to some gargantuan number, and it still gives me an HTTP status code 400 when I try to submit xml to the service. I turned on tracing, and the message tells me that it's still set to the default message size. This makes me think that the problem is some nuance in how I have my web.config set up. Could somebody take a quick peak at it and let me know what they think?
I've been around and around with this, and an extra set of eyes would be of great benefit to me. Thanks in advance!
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" openTimeout="00:25:00" closeTimeout="00:25:00" sendTimeout="00:25:00" receiveTimeout="00:25:00" maxBufferSize="2147483647">
<readerQuotas maxDepth="64"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="9000000"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147483647" transferMode="Streamed" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<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>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的OperationContract 属性是什么样的?
您是否在WebMessageFormat.Xml中设置了RequestFormat和ResponseFormat?
另外,您的 BodyStyle 应该是 WebMessageBodyStyle.WrappedRequest
由于没有条目,我假设您在 IIS 下运行它。
如果是这种情况,请确保您有正确配置的 .svc 文件。
另外,您可以检查 global.asax 以确保 url 实际上指向 wcf 服务。我只是猜测,但我确信它不是的一件事是消息大小属性
What does your OperationContract attribute look like?
Have you set the RequestFormat and ResponseFormat the WebMessageFormat.Xml?
Also, you BodyStyle should be WebMessageBodyStyle.WrappedRequest
Since there is no entry, I'm assuming you are running it under IIS.
if thats the case, make sure you have a properly configured .svc file.
Also, you might check your global.asax to make sure the url actually points to the wcf service. I'm just guessing but the one thing I'm sure its not is the message size property
好吧,我明白了;问题实际上出在客户端。它没有序列化我试图在 http 帖子中提交的对象。当我对照测试服务器上的服务检查它时,我更正了帖子的 xml,现在它可以正常工作了。谢谢!
OK, I figured it out; the problem was actually on the client. It wasn't serializing the object that I was trying to submit in the http post. When I checked it against a service on the test server, I corrected the xml for the post and now it's working properly. Thanks!