2016-09-05 4 views
4

WCFでStreamオブジェクトを受信しようとしていますが、受信したらストリームが閉じます。 以下は私のコードですWCF:閉鎖されたストリームにアクセスできない

[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", "[email protected]", 1211); 
+0

これを解決しましたか?私は現在同様の問題を抱えています。 – Jaans

+0

@Jaansはい私はしました。以下は私の問題を解決した解決策です。 –

答えて

0

を使用していました。ソリューションの次は私のために働いた。 代わりにパラメータとして直接ストリームを渡すので私が好きな応答を取得するためのパラメータやその他を渡すための2つのクラス1を作成しました。それから私は、WCFサービスで私の方法を更新

[MessageContract] 
    public class RemoteFileInfo : IDisposable 
    { 
     [MessageHeader(MustUnderstand = true)] 
     public string FileName; 

     [MessageHeader(MustUnderstand = true)] 
     public string DocType; 

     [MessageHeader(MustUnderstand = true)] 
     public string CustomerKey; 

     [MessageHeader(MustUnderstand = true)] 
     public string DocumentId; 

     [MessageBodyMember(Order = 1)] 
     public System.IO.Stream FileByteStream; 

     public void Dispose() 
     { 
      if (FileByteStream != null) 
      { 
       FileByteStream.Close(); 
       FileByteStream = null; 
      } 
     } 
    } 

[MessageContract] 
public class RemoteResponse 
{ 
    [MessageBodyMember(Order = 1)] 
    public string Token; 
} 

[OperationContract] 
RemoteResponse ProcessPackageUsingStream(RemoteFileInfo remote); 

そして、私のアプリを更新.config

<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_IPreProcessor" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" > 
     <readerQuotas maxDepth = "2147483647" 
      maxStringContentLength = "2147483647" 
      maxArrayLength = "2147483647" 
      maxBytesPerRead = "2147483647" 
      maxNameTableCharCount = "2147483647"/> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
関連する問題