2016-01-15 4 views
1

Я пытаюсь передать через WCF. Он работает в автономном режиме, но в IIS я получаю исключение в методе загрузки. Я установлен в True, возможность отладки на Web.cofig, чтобы получить лучшее понимание, но все это я получаю:Проблема с wcf-потоком по IIS

Необработанное исключение типа «System.ServiceModel.FaultException`1» произошло в mscorlib.dll Дополнительная информация : Дескриптор недействителен.

if (client.isItOpen()) 
{ 
    client.fileName(fileName); 
    FileStream instream1 = File.OpenRead(filePath);     
    bool result1 = client.UploadStream(instream1); 
    if (result1) 

Поскольку isItOpen() возвращает истину, есть связь со службой, но в UploadStream является исключением. Существуют ли определенные параметры, которые мне необходимо настроить в IIS, чтобы заставить его работать? Я помню, я менял лимит загрузки, но ничего больше. Файл, который я загружаю, небольшой, всего несколько КБ.

Клиент:

<system.serviceModel> 
    <bindings> 
    <basicHttpBinding> 
     <binding maxReceivedMessageSize="2147483647" transferMode="Streamed" /> 
    </basicHttpBinding> 
    </bindings> 
    <client> 
    <endpoint address="http://IP_HERE/SyncWCF/SyncService.svc/ep1" 
     binding="basicHttpBinding" contract="ISyncService" name="BasicHttpBinding_ISyncService" /> 
    </client> 
</system.serviceModel> 

if (client.isItOpen()) 
     { 
      client.fileName(fileName); 
      FileStream instream1 = File.OpenRead(filePath);     
      bool result1 = client.UploadStream(instream1); 
      if (result1) 
      { 
       StatusTextBox.AppendText("Done!" + Environment.NewLine); 
      } 
      instream1.Close(); 
     } 
     client.Close(); 

Услуги:

<system.serviceModel> 
<services> 
    <service name="SyncWCF.SyncService"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost/SyncService"/> 
     </baseAddresses> 
    </host> 
    <!-- this endpoint is exposed at the base address provided by host: http://localhost/ServiceModelSamples/service --> 
    <endpoint address="ep1" binding="basicHttpBinding" contract="SyncWCF.ISyncService"/> 
    <!-- the mex endpoint is exposed at http://localhost/SyncService/mex --> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 
<bindings> 
    <!-- an example basicHttpBinding using streaming --> 
    <basicHttpBinding> 
    <binding maxReceivedMessageSize="2147483647" transferMode="Streamed"/> 
    </basicHttpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 

public bool UploadStream(System.IO.Stream stream) 
    { 
     //this implementation places the uploaded file 
     //in the current directory and calls it "uploadedfile" 
     //with no file extension 
     string filePath = Path.Combine(System.Environment.CurrentDirectory, FileName); 
     try 
     { 
      Console.WriteLine("Saving to file {0}", filePath); 
      FileStream outstream = File.Open(filePath, FileMode.Create, FileAccess.Write); 
      //read from the input stream in 4K chunks 
      //and save to output stream 
      const int bufferLen = 4096; 
      byte[] buffer = new byte[bufferLen]; 
      int count = 0; 
      while ((count = stream.Read(buffer, 0, bufferLen)) > 0) 
      { 
       Console.SetCursorPosition(0, Console.CursorTop - 1); Console.WriteLine(buffer); 
       outstream.Write(buffer, 0, count); 
      } 
      outstream.Close(); 
      stream.Close(); 
      Console.WriteLine(); 
      Console.WriteLine("File {0} saved", filePath); 

      FileName = null; 
      return true; 
     } 
+1

1) Убедитесь, что путь правильный. 2) убедитесь, что учетная запись, с которой работает служба, имеет доступ к файлу. 3) поставить try/catch вокруг FileStream instream1 = File.OpenRead (filePath); поэтому вы можете поймать фактическое исключение. – dbugger

+0

Какая привязка вы используете? IIS не работает из-за-коробки с 'net.tcp'. – jsanalytics

+0

Это базовыйHttpBinding. – Ctrlfreak

ответ

1

System.ServiceModel.FaultException - The handle is invalid вызывается этой линии в вашей реализации услуг:

Console.SetCursorPosition(0, Console.CursorTop - 1); 

Просто снимите его.

Смежные вопросы