【发布时间】:2026-01-05 18:20:03
【问题描述】:
谢谢大家!
我们能够解决这个问题,只需将绑定元素名称从“basicHttpBinding”更改为“webHttpBinding”。
傻瓜,我知道..
你好,
我正在尝试使用 WCF 实现一个 Web 角色,它将接收 JSON 对象并将它们存储在 Azure 存储中。在集成测试期间,我收到了 400 错误代码。然后我发现 WCF 的消息大小非常小(~65535),我需要将其配置为更大。每当我尝试向我的服务发布 HTTP 请求(该请求永远不会到达我的代码)时,我当前使用的配置会导致 500 错误代码。
我使用的 Web.config 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxSizeOfMessageToLog="5000000" />
<endToEndTracing activityTracing="false" />
</diagnostics>
<services>
<service name="MyWebRole.RequestHandler" behaviorConfiguration="RequestHandlerbehavior">
<endpoint address="http://localhost:9001/" binding="basicHttpBinding" bindingConfiguration="conf" name="MyDefaultEndpoint"
contract="MyWebRole.IRequestHandler" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="conf" maxBufferSize="5000000" maxReceivedMessageSize="5000000" useDefaultWebProxy="true">
<readerQuotas maxDepth="5000000" maxStringContentLength="5000000" maxArrayLength="5000000" maxBytesPerRead="5000000" maxNameTableCharCount="5000000" />
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="RequestHandlerbehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
你能帮我把我的请求传递给我的 WCF 服务吗?
谢谢!
【问题讨论】:
-
你能用确切的错误信息更新你的问题吗?您可能可以在服务器上的事件日志中找到它。
-
突然想到如果你使用的是Azure存储,为什么要使用JSON?有更密集的序列化器......这会在一定程度上减少有效负载。