Tuesday, November 4, 2008

Adding Additional Debugging to a WCF call

I've recently been having a number of problems sending complex data types to a WCF service from an iPhone application I've been writing. I found this posting on the Apple site which increases the amount of debug information sent on each call.

// set debug props
WSMethodInvocationSetProperty(soapReq, kWSDebugIncomingBody, kCFBooleanTrue);
WSMethodInvocationSetProperty(soapReq, kWSDebugIncomingHeaders, kCFBooleanTrue);
WSMethodInvocationSetProperty(soapReq, kWSDebugOutgoingBody, kCFBooleanTrue);
WSMethodInvocationSetProperty(soapReq, kWSDebugOutgoingHeaders, kCFBooleanTrue);

Adding this to the genCreateInvocationRef method in your generated code from WSMakeStub did not require a lot of effort. I'd probably recommend it for each call.

e.g.

- (WSMethodInvocationRef) genCreateInvocationRef
{
WSMethodInvocationRef ref = [self createInvocationRef
/*endpoint*/: @"[URL]"
methodName: @"Generate"
protocol: (NSString*) kWSSOAP2001Protocol
style: (NSString*) kWSSOAPStyleDoc
soapAction: @"[method]"
methodNamespace: @"[namespace]"
];

WSMethodInvocationSetProperty(ref, kWSDebugIncomingBody, kCFBooleanTrue);
WSMethodInvocationSetProperty(ref, kWSDebugIncomingHeaders, kCFBooleanTrue);
WSMethodInvocationSetProperty(ref, kWSDebugOutgoingBody, kCFBooleanTrue);
WSMethodInvocationSetProperty(ref, kWSDebugOutgoingHeaders, kCFBooleanTrue);
return ref;

}