首页 > 代码库 > WPF+MVC+WCF大图片上传回显Demo

WPF+MVC+WCF大图片上传回显Demo

本实例讲WCF配置,MVC和WPF不作解释!

效果:

技术分享

 

Demo层次结构:

技术分享

 

MVC客户端:
连接WCF服务,将图片转换为Stream流,再将Stream流以byte[]方式进行图片上传!

核心代码

技术分享

 

WCF服务端:
以IIS为宿主,Http协议实现接收客户端的byte[]数据,返回给WPF客户端!
服务端Web.config配置十分重要,要做到大图片数据传输,需要给在binding添加
<binding name="ImageOperationService_Binding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>

system.web节点下添加
<system.web>
    <compilation debug="true"/>
     <httpRuntime maxRequestLength="2097151" executionTimeout="1200"/>
  </system.web>

 

客户端同样需要配置相同信息

---------------------------------------------------------------------以下是服务端配置代码---------------------------------------------------------------------
<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ImageOperationService_Behavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="ImageOperationService_Binding" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ImageOperationService_Behavior" name="LshDemo.Service.ImageOperationService">
        <endpoint address="http://192.168.1.75/ImageOperationService.svc" binding="basicHttpBinding" bindingConfiguration="ImageOperationService_Binding" contract="LshDemo.Service.IImageOperationService"/>
      </service>
    </services>
  </system.serviceModel>
  <system.web>
    <compilation debug="true"/>
     <httpRuntime maxRequestLength="2097151" executionTimeout="1200"/>
  </system.web>
</configuration>

WPF客户端:
启动线程监听WCF服务图片信息,及时读取WCF服务字节流,在界面显示!

核心代码:

 

技术分享

Demo下载链接:http://yunpan.cn/cfpygtIvCqjUv ;
提取码 b289

 

WPF+MVC+WCF大图片上传回显Demo