none
File stream problem

    Question

  • I'm trying to transfer file with WCF, but I can't get it to work.
    Idea is to use MTOM to transfer the file.
    I have read some examples, but still I have the same problem.
    "The operation is not supported by WCF"

    Here's the source code.

    namespace Palvelin 
        [ServiceContract()] 
        public interface IMessageTransfer 
        { 
            [OperationContract(IsOneWay = true)] 
            void SendFile(FileMessage fileMessage); 
        } 
     
        [MessageContract()] 
        public class FileMessage 
        { 
            [DataMember] 
            public string name; 
     
            [DataMember] 
            public System.IO.Stream fileStream; 
        } 

    namespace Palvelin 
        public class MessageTransfer : IMessageTransfer 
        { 
            public void SendFile(FileMessage fileMessage) 
            { 
                Console.WriteLine("Test"); 
            } 
        } 
     

    And the App.config

    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
      <system.web> 
        <compilation debug="true" /> 
      </system.web> 
      <!-- When deploying the service library project, the content of the config file must be added to the host's  
      app.config file. System.Configuration does not support config files for libraries. --> 
      <system.serviceModel> 
        <bindings> 
          <basicHttpBinding> 
              <!-- buffer: 64KB; max size: 64MB --> 
              <binding name="FileTransferServicesBinding" transferMode="Streamed" messageEncoding="Mtom" maxBufferSize="65536" maxReceivedMessageSize="67108864"
                <security mode="None"
                  <transport clientCredentialType="None"/> 
                </security> 
              </binding> 
          </basicHttpBinding> 
        </bindings> 
        <services> 
          <service behaviorConfiguration="Palvelin.MessageTransferBehavior" name="Palvelin.MessageTransfer"
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="FileTransferServicesBinding" name="Palvelin" contract="Palvelin.IMessageTransfer" /> 
              <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
            <host> 
              <baseAddresses> 
                <add baseAddress="http://localhost:8731/Design_Time_Addresses/Palvelin/SanomanValitys/" /> 
              </baseAddresses> 
            </host> 
          </service> 
        </services> 
        <behaviors> 
          <serviceBehaviors> 
            <behavior name="Palvelin.MessageTransferBehavior"
              <!-- To avoid disclosing metadata information,  
              set the value below to false and remove the metadata endpoint above before deployment --> 
              <serviceMetadata httpGetEnabled="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> 
      </system.serviceModel> 
    </configuration> 
     



    Tuesday, December 02, 2008 8:58 AM

All replies

  • When exactly do you get this error? e.g. in run time or when accessing the WSDL?

    I think that when one of the contract parameters is Stream then it has to be the only parameter. You should change it to byte[].

    http://webservices20.blogspot.com/
    WCF Security, Performance And Testing Blog
    Tuesday, December 02, 2008 12:10 PM
  • Hi,

    You have to change this code,

     [MessageContract()] 
        public class FileMessage 
        { 
            [DataMember] 
            public string name; 
     
            [DataMember] 
            public System.IO.Stream fileStream; 
        } 

    By :

    [MessageContract()] 
        public class FileMessage 
        { 
            [MessageHeader] 
            public string name; 
     
            [MessageBodyMember] 
            public System.IO.Stream fileStream; 
        } 

    When you use streams, only the stream can go in the body element.

    Regards,
    Pablo.
    Pablo Cibraro - http://weblogs.asp.net/cibrax
    Tuesday, December 02, 2008 1:09 PM
  • I changed the code, but it still gives me the same error.

    It gives the error when I compile the solution, and the WCF Test Client pops up.
    And the SendFile function has a red ball next to it.

    Tuoski's Blog - http://www.tuoski.net/
    Wednesday, December 03, 2008 8:11 AM
  • Hi,

     If the project doesn't compile - what is the exact compiler error you experience?

     --larsw

    Lars Wilhelmsen | Senior Consultant | Miles, Norway | MCTS WCF | http://larswilhelmsen.com/
    Wednesday, December 03, 2008 9:35 AM
  • Sorry, it compiles but it pops up the WCF Test Client and gives the error.
    Tuoski's Blog - http://www.tuoski.net/
    Thursday, December 04, 2008 6:03 AM
  • -> Sorry, it compiles but it pops up the WCF Test Client and gives the error.

    Then what's the error, care to elaborate it a little bit?

    Thanks

    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Thursday, December 04, 2008 8:57 AM
  • Again, it gives the error when I compile the solution, and the WCF Test Client pops up.
    And the SendFile function has a red ball next to it.
    The error is "The operation is not supported by WCF".


    Tuoski's Blog - http://www.tuoski.net/
    Thursday, December 04, 2008 1:19 PM
  • Then, could you please provide a small, complete and ready-to-run example to demonstrate the issue you are encountering?

     

    Thanks


    Another Paradigm Shift
    http://shevaspace.blogspot.com
    Friday, December 05, 2008 7:09 AM
  • The example is in the first post.
    Or do you want the whole project?

    Tuoski's Blog - http://www.tuoski.net/
    Friday, December 05, 2008 7:25 AM
  • did you change the transport type to stream ? (rather than messges)
    Friday, December 05, 2008 10:25 AM
  • You mean transferMode="Streamed"?
    And yes it is streamed, just like in the app.config.

    Tuoski's Blog - http://www.tuoski.net/
    Monday, December 08, 2008 7:15 AM