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