我正在为我的 Web 服务使用 WCF SOAP 服务,我想从 Web 服务将文件作为流返回问题是文件数据最终出现在我不希望的肥皂信封中,我只想让文件流成为回来了,有人可以帮忙吗,这是我目前所拥有的。
[OperationContract]
Stream GetDocument();
public Stream GetDocument()
{
string filePath = @"C:/Temp/test.txt";
try
{
System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
System.IO.FileStream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
return stream;
}
catch (Exception ex)
{
throw ex;
}
}
网络配置
<behaviors>
<serviceBehaviors>
<behavior name="BasicBinding.ServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding"
closeTimeout="01:01:00"
openTimeout="01:01:00"
receiveTimeout="01:01:00"
sendTimeout="01:01:00"
allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647"
maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647"
messageEncoding="Text"
textEncoding="utf-8"
transferMode="Streamed"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="BasicBinding.ServiceBehavior" name="Service">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding"
bindingNamespace=""
contract="IService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
回复
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetDocumentResponse>
<GetDocumentResult>dGVzdCB0ZXN0IHRlc3QgdGVzdA==</GetDocumentResult>
</GetDocumentResponse>
</s:Body>
</s:Envelope>
所以我想要的只是将文件作为流而不是在肥皂信封中返回,有人可以帮忙吗?