我在一方有一个wcf服务,在客户端有一个mvc网站。我需要从wcf驻留到mvc客户端的服务器下载文件,然后用户可以从Web应用程序下载该文件。我在wcf上有一个LinkStream
消息合约。由下面的fileInfo
对象表示的文件包含1 gig的数据。
return new LinkStream { Stream = fileInfo.OpenRead(), Instant = true };
当客户端进行此调用时,我检查服务器上的Windows任务管理器,并且我看到内存使用高峰,它会上升超过4gig然后回落到原来的状态并关闭连接并抛出以下异常在客户端:
The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:
'<!DOCTYPE html>
<html>
<head>
<title>Overflow or underflow in the arithmetic operation.</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font- size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
@media screen and (max-width: 639p'.
以下是我在wcf和mvc方面的配置文件:
WCF:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="LinkEndBinding" receiveTimeout="00:05:10" sendTimeout="00:05:30"
transferMode="Streamed" maxBufferSize="65536" maxReceivedMessageSize="1288490188" useDefaultWebProxy="false" >
<readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Links.Links" >
<endpoint binding="basicHttpBinding" bindingName="LinkEndBinding" contract="Links.ILinks" />
</service>
</services>
</system.serviceModel>
MVC:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="LinkEndBinding_ILinks" receiveTimeout="00:05:10" sendTimeout="00:05:30" transferMode="Streamed" maxBufferSize="65536" maxReceivedMessageSize="1288490188" useDefaultWebProxy="false">
<security mode="None" />
<readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646" maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="<myUrl>/Core.Links.Implementation/Links.svc" binding="basicHttpBinding" bindingConfiguration="LinkEndBinding_ILinks" contract="LinkService.ILinks" name="LinkEndBinding_ILinks" />
</client>
</system.serviceModel>
消息合同:
[MessageContract]
public class LinkStream : IDisposable
{
[MessageHeader(MustUnderstand = true)]
public bool Instant { get; set; }
[MessageBodyMember]
public Stream Stream { get; set; }
public void Dispose ()
{
Stream.Close();
}
}
我真的很困惑。并接受任何建议:)