我正在为我的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;
}
}
的web.config
<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>
所以我想要的是将文件作为流而不是肥皂信封返回,有人可以帮忙吗???