Crash with WSMethodInvocationInvoke and malformed XML

I’ve been doing some stuff recently with XMLRPC for both SQLEditor and an unannounced new product.

One of the key parts of XMLRPC in cocoa is the Apple web services Core. It provides almost everything you need to use web services.

However I did discover one oddity that led to some puzzelment

As part of my development I’d written a test server in php which operates a few simple functions that the client can try. This means that I can simulate various commands and cause intentional failures to see what happens. I also have a php client to check the server independently.

I had been making alterations to check a particular function in the client worked correctly. It was a new function that provided an array of values that could be placed into a menu on the client. The idea seemed sounds, the design had been worked out and new functionality had been added to both client and server. The server seemed to work fine with its test client and I was ready to try my main client application.

Unfortunately it either crashed or generated an exception on every call to WSMethodInvocationInvoke. Initally I assumed that it was a bug with my client application, perhaps I’d passed in the wrong arguments or made a mistake in setting up the context for the call.

However after some testing of various possibilities I discovered what seems to be the actual cause.

One of the included php files contained an extra new line character at the top before the doctype.

Removing this extra new line solved the problem
(presumably because it was now valid XML).

Moral of this story:

XMLRPC implementations and XML parsers are not always very forgiving of whitespace at the top.

Interestingly, the xml parser in camino doesn’t like xml files with extra lines at the top either.

I’m still looking to see if there is some setting that can be changed to make the parser more forgiving, or to pre-process the xml first.

(I’ll be reporting this issue as soon as I can produce a suitable test case)

This entry was posted in Macintosh, Writing Software. Bookmark the permalink.

Leave a Reply