文件从 ClientBase上传到 WCF 服务
我目前正在开发一种将文件上传和下载到 WCF 服务的解决方案。客户端是一个继承自ClientBase的类。我已阅读关于流式传输的 MSDN 文章以及 StackOverflow 和其他地方的链接,但我似乎无法弄清楚为什么我仍然收到有关消息大小太小的消息。到目前为止,我已经用小文件测试了该解决方案,并且它有效。
该服务托管在 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") {}
}
所以有什么想法我可能会出错吗?任何帮助表示赞赏。
-谢谢!
I'm currently working on a solution to upload and download files to a WCF service. The client is a class inheriting from ClientBase. I've read the MSDN article on streaming and links on StackOverflow and elsewhere, but I can't seem to figure out why I'm still getting a message about the Message size being too small. I have tested the solution so far with small files and it works.
The service is hosted in IIS 7.5
Here's the App.config from the Client application
<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>
Here are the relevant sections in the server
<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>
Additionally, I've added the following in on both server and client configs:
<system.web>
<httpRuntime maxRequestLength="2147483647" />
</system.web>
This is how I'm instantiating the client
public class UpdateClient : ClientBase<IUpdateService>, IUpdateService
{
public UpdateClient() : base("updateServiceEndpoint") {}
}
So does have any ideas where I could be going wrong? Any help is appreciated.
-Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到答案 - 一个非常简单的错误,客户端/端点条目缺少绑定配置属性
Found the answer - a very simple mistake, the client/endpoint entry was missing the bindingConfiguration attribute