【发布时间】:2011-11-12 05:44:21
【问题描述】:
我目前正在研究一种将文件上传和下载到 WCF 服务的解决方案。客户端是一个继承自 ClientBase 的类。我已经阅读了有关 StackOverflow 和其他地方的流式传输和链接的MSDN article,但我似乎无法弄清楚为什么我仍然收到有关消息大小太小的消息。到目前为止,我已经使用小文件测试了该解决方案,并且可以正常工作。
服务托管在 IIS 7.5 中
这是来自客户端应用程序的 App.config
<system.web>
<httpRuntime maxRequestLength="67108864" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding messageEncoding="Mtom" transferMode="Streamed" name="LargeFileStreamingHttpBinding"
maxBufferSize="65536"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/UpdateService.svc"
binding="basicHttpBinding"
contract="IUpdateService"
name="updateServiceEndpoint"/>
</client>
</system.serviceModel>
这是服务器中的相关部分
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="UpdateService" behaviorConfiguration="UpdateServiceBehavior">
<endpoint binding="basicHttpBinding" bindingName="LargeFileStreamingWebHttpBinding" contract="IUpdateService"></endpoint>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="UpdateServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding messageEncoding="Mtom" transferMode="Streamed" name="LargeFileStreamingWebHttpBinding"
maxBufferSize="65536"
maxReceivedMessageSize="2147483647"
/>
</basicHttpBinding>
</bindings>
</system.serviceModel>
此外,我在服务器和客户端配置中都添加了以下内容:
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
这就是我实例化客户端的方式
public class UpdateClient : ClientBase<IUpdateService>, IUpdateService
{
public UpdateClient() : base("updateServiceEndpoint") {}
}
那么有什么想法我可能会出错吗?任何帮助表示赞赏。
-谢谢!
【问题讨论】:
-
服务类名称只是“UpdateService”,还是属于某个命名空间?如果是后者,您需要在
<service name="fully_qualified_name_of_service">上具有完全限定名称,以便它获取配置。 -
为简洁起见,我省略了服务合同命名空间
-
投票关闭,因为过于本地化,因为没有其他人会犯这个特殊错误,不会通过搜索这个问题找到答案。
-
您的问题标题描述了您的服务内容,而不是您的问题或问题的性质。建议您让它更准确地反映您的问题/问题。
-
我同意。我最初认为这个实现的问题是技术问题,但后来发现这是我的一个简单错误。我应该自己关闭/删除这个问题。
标签: wcf wcf-client