0

I'm trying to use sync through an IIS 8 Webdav backend with Ensembles. The problem i encounter is that the first sync works fine, but when i try to sync a second time or on a second unit (iPad in this case) I get a server error 405 "method not allowed". Has anyone encountered this and got it working, to sync with IIS Webdav?

This is the allheaderfield property of the server response:

" UserInfo={NSLocalizedDescription=HTTP status code was {
    Allow = "COPY, PROPFIND, DELETE, MOVE, PROPPATCH, LOCK, UNLOCK";
    Connection = "Keep-Alive";
    "Content-Length" = 1293;
    "Content-Type" = "text/html";
    Date = "Mon, 25 Jan 2016 12:02:07 GMT";
    "Persistent-Auth" = true;
    Server = "Microsoft-IIS/8.5";
    "X-UA-Compatible" = "IE=8";

EDIT: It might be possible that this isn't a configuration problem after all. I added a few logs and the createDirectoryAtPath method gives me HTTP error 405, this is the original code:

- (void)createDirectoryAtPath:(NSString *)path completion:(CDECompletionBlock)completion{
NSMutableURLRequest *request = [self mutableURLRequestForPath:path];
request.HTTPMethod = @"MKCOL";
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];

[self sendURLRequest:request completion:^(NSError *error, NSInteger statusCode, NSData *responseData) {
    if (completion) completion(error);
}];}

And this is the directoryExistsAtPath method:

- (void)directoryExistsAtPath:(NSString *)path completion:(CDEDirectoryExistenceCallback)completion{
[self sendPropertyFindRequestForPath:path depth:0 completion:^(NSError *error, NSInteger statusCode, NSData *responseData) {
    if (error && statusCode != 404) {
        if (completion) completion(NO, error);
    }
    else if (statusCode == 404) {
        if (completion) completion(NO, nil);
    }
    else {
        CDEWebDavResponseParser *parser = [[CDEWebDavResponseParser alloc] initWithData:responseData];
        BOOL succeeded = [parser parse:&error];
        if (!succeeded) {
            if (completion) completion(NO, error);
            return;
        }

        BOOL isDir = [parser.cloudItems.lastObject isKindOfClass:[CDECloudDirectory class]];
        if (completion) completion(isDir, nil);
    }
}];}

If i replace the first parameter (currently the isDir-variable) in the completion block at the end to YES, the 405 error does not appear.On logging the parser.clouditems.lastobject, I find that it is often (or always?) empty). So setting the parameter to YES, results in data being uploaded to my webdav, and the folders are in place. However, testing on a second unit (or reinstalling the app on the same unit), download never happens - the downloadFromPath never gets called, a "GET"-request is never sent.

Looking at the calling code in the underlying framework (CDECloudmanager mostly) hasn't led me anywhere so far.

As the directoryExistsAtPath is optional, i tried commenting it out, but i don't think it made a difference.

Another thing I noticed is that I get several baseline files in the baselines folder. According to the Ensembles documentation, there should only be one.

Any clues?

Mathias Åberg
  • 99
  • 1
  • 10
  • Can you perhaps try to figure out which method that is? – Drew McCormack Jan 22 '16 at 11:55
  • I made a log of the allHeaderFields property of the response, i will paste in the original post. – Mathias Åberg Jan 25 '16 at 12:16
  • I'm logging the verbs used in the CDEWebDavCloudFileSystem file, and so far it looks like PUT works but not MKCOL. – Mathias Åberg Jan 25 '16 at 13:42
  • I can see now that MKCOL does work, the "method not allowed" on MKCOL comes up when i try to sync on the second iPad. – Mathias Åberg Jan 25 '16 at 15:55
  • Hmm, I am certainly no WebDAV expert, I'm afraid. It seems it does vary a little from platform to platform. The code is all there, so I would recommend setting some breakpoints, and seeing if you can see where in the class the error arises, and maybe google for why. – Drew McCormack Jan 26 '16 at 13:22
  • Just looked at the code. So MKCOL is used to make a directly. Maybe see if you can just replace that with a PUT, or whatever IIS expects for making directories. If it works, let me know, and I'll try to work it in to the code. – Drew McCormack Jan 26 '16 at 13:26
  • Editing in some code above, this might not be a configuration problem after all – Mathias Åberg Feb 02 '16 at 07:58
  • Multiple baseline files can be normal, depending on how much data you have. Ensembles now splits it up so they can be loaded one at a time, without excessive memory use. – Drew McCormack Feb 03 '16 at 08:28
  • Maybe it is best to contact me by email. This is getting a bit too complex for comments on SO. – Drew McCormack Feb 03 '16 at 08:34
  • On second reading, it sounds like it automatically creates directories as needed. Is that right? Maybe if directoryExistsAtPath: just always fires back YES immediately, it will work. – Drew McCormack Feb 03 '16 at 08:51
  • Replacing isDir with YES in the call to the completion block, fixes the 405 error, but instead I get this problem that the apps don't sync between devices. A new baseline is made for each new device. I'm really in the dark here - but great! I'll email you and maybe I can elaborate a bit. – Mathias Åberg Feb 03 '16 at 09:08

1 Answers1

1

Ok seems I got this working at last. I had to make a change in the CDEWebDavCloudFileSystem class to avoid the 405 error. Doing that however, I encountered a 404 error. That one was solved by configuring the IIS webdav.

So step 1, I changed the request in the sendPropertyFindRequestForPath method:

new code:

static NSString *xml = @"<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"><D:allprop/></D:propfind>";

original code:

static NSString *xml = @"<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\"><D:prop><D:href/><D:resourcetype/><D:creationdate/><D:getlastmodified/><D:getcontentlength/><D:response/></D:prop></D:propfind>";

To remove the 404 error appearing after that I had to add mime type application/xml to the .cdeevent extension.

This link goes into detail of how to configure IIS for that:

http://anandthearchitect.com/2013/08/01/webdav-404file-or-directory-not-found/

Mathias Åberg
  • 99
  • 1
  • 10