化零为整WCF(8) - 消息处理(使用流数据传输文件)
2008-04-21 08:52
477 查看
[索引页]
[源码下载]
[align=center]化零为整WCF(8) - 消息处理(使用流数据传输文件)[/align]
作者:webabcd
介绍
WCF(Windows Communication Foundation) - 消息处理:使用流数据传输文件,减少内存开销。
示例
1、服务
IStreamed.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
namespace WCF.ServiceLib.Message
Streamed.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
namespace WCF.ServiceLib.Message
2、宿主
Streamed.cs
using (ServiceHost host = new ServiceHost(typeof(WCF.ServiceLib.Message.Streamed)))
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!--name - 提供服务的类名-->
<!--behaviorConfiguration - 指定相关的行为配置-->
<service name="WCF.ServiceLib.Message.Streamed" behaviorConfiguration="MessageBehavior">
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<!--bindingConfiguration - 指定相关的绑定配置-->
<endpoint address="Message/Streamed" binding="netTcpBinding" contract="WCF.ServiceLib.Message.IStreamed" bindingConfiguration="StreamedBindingConfiguration" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Message/Streamed/"/>
<add baseAddress="net.tcp://localhost:54321/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MessageBehavior">
<!--httpGetEnabled - 使用get方式提供服务-->
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<!--transferMode - 指示通道是使用流处理模式还是缓冲模式来传输请求和响应消息-->
<!--maxReceivedMessageSize - 在采用此绑定配置的通道上可接收的最大消息大小(单位:字节)-->
<!--receiveTimeout - 在传输引发异常之前可用于完成读取操作的时间间隔-->
<binding name="StreamedBindingConfiguration" transferMode="Streamed" maxReceivedMessageSize="1073741824" receiveTimeout="00:10:00" />
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
3、客户端
Streamed.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using System.IO;
namespace Client2.Message
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<endpoint address="net.tcp://localhost:54321/Message/Streamed" binding="netTcpBinding" contract="MessageSvc.Streamed.IStreamed" bindingConfiguration="StreamedBindingConfiguration" />
</client>
<bindings>
<netTcpBinding>
<!--transferMode - 指示通道是使用流处理模式还是缓冲模式来传输请求和响应消息-->
<!--sendTimeout - 在传输引发异常之前可用于完成写入操作的时间间隔-->
<binding name="StreamedBindingConfiguration" transferMode="Streamed" sendTimeout="00:10:00" />
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
运行结果:
上传文件后提示上传成功
OK
[源码下载]
[源码下载]
[align=center]化零为整WCF(8) - 消息处理(使用流数据传输文件)[/align]
作者:webabcd
介绍
WCF(Windows Communication Foundation) - 消息处理:使用流数据传输文件,减少内存开销。
示例
1、服务
IStreamed.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
namespace WCF.ServiceLib.Message
Streamed.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.IO;
namespace WCF.ServiceLib.Message
2、宿主
Streamed.cs
using (ServiceHost host = new ServiceHost(typeof(WCF.ServiceLib.Message.Streamed)))
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!--name - 提供服务的类名-->
<!--behaviorConfiguration - 指定相关的行为配置-->
<service name="WCF.ServiceLib.Message.Streamed" behaviorConfiguration="MessageBehavior">
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<!--bindingConfiguration - 指定相关的绑定配置-->
<endpoint address="Message/Streamed" binding="netTcpBinding" contract="WCF.ServiceLib.Message.IStreamed" bindingConfiguration="StreamedBindingConfiguration" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Message/Streamed/"/>
<add baseAddress="net.tcp://localhost:54321/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MessageBehavior">
<!--httpGetEnabled - 使用get方式提供服务-->
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<!--transferMode - 指示通道是使用流处理模式还是缓冲模式来传输请求和响应消息-->
<!--maxReceivedMessageSize - 在采用此绑定配置的通道上可接收的最大消息大小(单位:字节)-->
<!--receiveTimeout - 在传输引发异常之前可用于完成读取操作的时间间隔-->
<binding name="StreamedBindingConfiguration" transferMode="Streamed" maxReceivedMessageSize="1073741824" receiveTimeout="00:10:00" />
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
3、客户端
Streamed.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using System.IO;
namespace Client2.Message
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<!--address - 服务地址-->
<!--binding - 通信方式-->
<!--contract - 服务契约-->
<endpoint address="net.tcp://localhost:54321/Message/Streamed" binding="netTcpBinding" contract="MessageSvc.Streamed.IStreamed" bindingConfiguration="StreamedBindingConfiguration" />
</client>
<bindings>
<netTcpBinding>
<!--transferMode - 指示通道是使用流处理模式还是缓冲模式来传输请求和响应消息-->
<!--sendTimeout - 在传输引发异常之前可用于完成写入操作的时间间隔-->
<binding name="StreamedBindingConfiguration" transferMode="Streamed" sendTimeout="00:10:00" />
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
运行结果:
上传文件后提示上传成功
OK
[源码下载]
相关文章推荐
- 化零为整WCF(8) - 消息处理(使用流数据传输文件)
- 化零为整WCF(8) - 消息处理(使用流数据传输文件)
- 化零为整WCF(7) - 消息处理(使用消息传输优化机制 - MTOM)
- 化零为整WCF(7) - 消息处理(使用消息传输优化机制 - MTOM)
- 化零为整WCF(7) - 消息处理(使用消息传输优化机制 - MTOM)
- 传输参数【JAX-WS入门系列】第06章_使用MTOM处理二进制文件
- 化零为整WCF(6) - 消息处理(异步调用OneWay, 双向通讯Duplex)
- WCF使用NetTcp传输文件
- 化零为整WCF(6) - 消息处理(异步调用OneWay, 双向通讯Duplex)
- 一起谈.NET技术,WCF使用NetTcp传输文件
- C# 的 WCF文章 消息契约(Message Contract)在流(Stream )传输大文件中的应用
- WCF中使用MTOM消息传输优化机制
- 发现使用wcf传输的文件有20K的丢失
- WCF开发-使用证书文件配置基于自定义X509证书验证的消息安全模式
- 化零为整WCF(6) - 消息处理(异步调用OneWay, 双向通讯Duplex)
- WCF使用NetTcp传输文件
- Android异步消息处理机制(1)Handler基本使用
- 使用SerialPort传输图片文件的实验
- 使用Python命令在Linux系统之间传输文件
- Apache CXF实战之七 使用Web Service传输文件