in

dotNet Umbria

Il primo User Group in Umbria sul mondo .Net
Latest post 07-21-2008 1:48 PM by belius. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 07-21-2008 1:48 PM

    • belius
    • Top 10 Contributor
    • Joined on 11-16-2007
    • Perugia

    Wcf Mtom e Streaming

    Ciao a tutti,

    sto cercando di fare un Servizio WCF che permetta di fare Upload/Download di grossi file correlati ad un record di un DB da piattaforme eterogenee (.NET e non).
    Per fare ciò ho creato un MessageContract che espone nell'header le proprietà a me necessarie per il riferimento nel DB e una proprietà nel body che rappresenta l'oggetto Stream.

    Il binding che devo utilizzare è il wsHttpBinding che di default non permette di fare Streaming, quindi ho implementato un customBinding che permetta di fare l'encoding del messaggio in formato Mtom e che come trasporto Http faccia streaming.

    MessageContract

     [MessageContract]
        public class DocumentMessage
        {
            [MessageHeader(MustUnderstand = true)]
            public string FileName;

            [MessageHeader(MustUnderstand = true)]
            public long Length;

            [MessageHeader(MustUnderstand = true)]
            public int Id;

            [MessageHeader(MustUnderstand = true)]
            public int RelatedObjectId;

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

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

     SERVIZIO

    [ServiceContract]
        public interface IDocumentService
        {
            [OperationContract]
            void UploadFile(DocumentMessage request);
        }

    CONFIGURAZIONE SERVER

        <system.serviceModel>
      <bindings>
       <customBinding>
        <binding name="wsDocumentCustomBinding">
         <mtomMessageEncoding />
         <httpTransport maxReceivedMessageSize="10067108864" transferMode="Streamed" />
        </binding>
       </customBinding>
      </bindings>
      <services>
       <service behaviorConfiguration="mexBehavior" name="WcfDocumentService.DocumentService">
        <endpoint address="DocumentService" binding="customBinding" bindingConfiguration="wsDocumentCustomBinding"
         name="wsHttpDocumentServiceEP" contract="WcfDocumentService.IDocumentService" />
        <host>
         <baseAddresses>
          <add baseAddress="http://localhost:2196/" />
         </baseAddresses>
        </host>
       </service>
      </services>
      <behaviors>
       <serviceBehaviors>
        <behavior name="mexBehavior">
         <serviceMetadata httpGetEnabled="true"/>
        </behavior>
       </serviceBehaviors>
      </behaviors>
     </system.serviceModel>

     

    CONFIGURAZIONE CLIENT 

     <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="wshttpdocumentservice">
                        <mtomMessageEncoding />
                        <httpTransport maxReceivedMessageSize="10067108864" transferMode="Streamed" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:2196/DocumentService.svc/DocumentService"
                    binding="customBinding" bindingConfiguration="wshttpdocumentservice"
                    contract="IDocumentService" name="wsDocumentService" />
            </client>
        </system.serviceModel>

     

    Il progetto viene compilato correttamente e anche la definizione del WSDL si vede senza problemi.

    Il problema è quando richiamo il servizio dal client che mi viene restituito il seguente errore:

    The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

    A qualcuno è mai capitato questa problematica?

    Ogni consiglio.....anche suggerimenti per qualche altra soluzione (tenendo in considerazione lo streaming/chunking di messaggi di grandi dimenzioni su Http)  è ben accetta.

     

    ciao

    simone

     

     

     

    Simone Belia Blog: Belius
Page 1 of 1 (1 items)
dotNet Umbria 2007-2008
Powered by Community Server (Commercial Edition), by Telligent Systems