none
404 when uploading changes RRS feed

  • Question

  • If I can use a sync service to create a database schema and download data, why does it return a 404 when I try to upload data?

    I am using sync framework in an application to synchronize data between workstations and a central server. As long as I download data from the server (create new database on local machine and download data into the new tables), everything works fine. All subsequent download only syncs work fine. If I configure the application to do a download only sync instead of a bidirectional sync, everything works fine. However, if I try to switch over to a bidirectional sync, the upload step does not work. Instead of uploading data, my server returns a 404, even though my sync clients have been able to locate the service just fine every other time.

    Here is the relevant portion of my Web.config:

    <services>
        <service name="Services.Services.DataCacheSyncService"
                 behaviorConfiguration="default">
            <endpoint binding="wsHttpBinding"
                      contract="Synchronization.Services.Contracts.IDataCacheSyncContract" />
      </service>
    </services>

    Here is the SVC file used to access the service:

    <%@ ServiceHost Service="Services.Services.DataCacheSyncService" %>

    And here are my data contracts:

    [ServiceContract]
    public interface IDataCacheSyncContract : IDataCacheUploadContract, IDataCacheDownloadContract
    {
    }
    
    [ServiceContract]
    public interface IDataCacheUploadContract : IDataCacheContract
    {
        [FaultContract(typeof(string))]
        [OperationContract]
        SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession);
    }
    
    [ServiceContract]
    public interface IDataCacheDownloadContract : IDataCacheContract
    {
        [FaultContract(typeof(string))]
        [OperationContract]
        SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession);
    }
    
    [ServiceContract]
    public interface IDataCacheContract
    {
        [OperationContract]
        SyncSchema GetSchema(IEnumerable<string> tableNames, SyncSession syncSession);
    
        [OperationContract]
        SyncServerInfo GetServerInfo(SyncSession syncSession);
    }
    Tuesday, March 27, 2012 10:51 PM

Answers

  • It seems that I need to modify the Web.config a bit:

    <!-- Setting maxReceivedMessageSize ensures that we do not encounter 404 errors when uploading large amounts of data -->
    <system.serviceModel>
      <bindings>
        <wsHttpBinding>
          <binding maxReceivedMessageSize="2147483647"
                   name="wsBindingWithLargeUploadLimit"
                   sendTimeout="00:10:00" />
        </wsHttpBinding>
      </bindings>
      <services>
        <service name="Services.Services.DataCacheSyncService"
                 behaviorConfiguration="default">
          <endpoint binding="wsHttpBinding"
                    bindingConfiguration="wsBindingWithLargeUploadLimit"
                    contract="Synchronization.Services.Contracts.IDataCacheSyncContract" />
        </service>
      </services>
    </system.serviceModel>

    If the message is larger than the maxReceivedMessageSize (defaults to 2^16, I believe), a 404 will be returned.

    That's not the best choice of error code, in my opinion. A 413 would be somewhat more explicit about the reason for failure.

    • Marked as answer by Karl Dickman Wednesday, March 28, 2012 11:37 PM
    Wednesday, March 28, 2012 11:37 PM