【发布时间】:2017-01-12 11:49:00
【问题描述】:
我试图在 WCF 中接收一个 Stream 对象,但是当我收到它时,我得到一个关闭的 Stream。 以下是我的代码
[OperationContract]
string ProcessPackageUsingStream(FileStream stream, string fileName, string docType, string customerKey, int documentId);
在实现中我正在使用这个流对象。
string ProcessPackageUsingStream(FileStream stream, string fileName, string docType, string customerKey, int documentId);
{
//Stream is closed here
}
这是我的配置文件
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="TransferService" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="TransferServiceBehavior" name="TransferService">
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration="TransferService"
contract ="ITransferService">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="TransferServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling
maxConcurrentCalls="500"
maxConcurrentSessions="500"
maxConcurrentInstances="500"
/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
在客户端,我添加了对该服务的引用并使用了以下代码
SPCServiceClient service = new SPCServiceClient();
service.ProcessPackageUsingStream(File.OpenRead(@"D:\Dev\TestData\002160500041.pdf"), "002160500041.pdf", "Test", "VLR@2016", 1211);
【问题讨论】:
-
你解决过这个问题吗?我目前有类似的问题。
-
@Jaans 是的,我做到了。以下是解决我的问题的解决方案。