Monday, July 6, 2009

提及點用cfnetwork

Sending SMS via Soap from Cocoa (Mac)

Here is some code that was used as part of my IPhone App for sending SMS messages via SOAP;

Full download can be found here;http://sites.google.com/site/freesmsuk/free-sms-iphone-app

#import "sendSms.h"
#import
#import
#import



@implementation sendSms_SendSms


@synthesize fromName;
@synthesize fromNumber;
@synthesize toNumber;
@synthesize message;
@synthesize locale;

- (id)init
{
if((self = [super init])) {
}

return self;
}


- (void)dealloc
{

[super dealloc];
}


- (NSString *)nsPrefix
{
return @"sendSms";
}


- (NSString *)serializedFormUsingElementName:(NSString *)elName
{
NSMutableString *serializedForm = [NSMutableString string];

[serializedForm appendFormat:@"<%@ xsi:type=\"sendSms:SendSms\"", elName];
[serializedForm appendString:[self serializedAttributeString]];
[serializedForm appendFormat:@">"];

[serializedForm appendString:[self serializedElementString]];

[serializedForm appendFormat:@"\n", elName];

return serializedForm;
}


- (NSString *)serializedAttributeString
{
NSMutableString *serializedForm = [NSMutableString string];



return serializedForm;
}


- (NSString *)serializedElementString
{
NSMutableString *serializedForm = [NSMutableString string];


[serializedForm appendFormat:@"\n"];
[serializedForm appendFormat:fromName];
[serializedForm appendFormat:@"
\n"];

[serializedForm appendFormat:@""];
[serializedForm appendFormat:fromNumber];
[serializedForm appendFormat:@"
\n"];

[serializedForm appendFormat:@""];
[serializedForm appendFormat:toNumber];
[serializedForm appendFormat:@"
\n"];

[serializedForm appendFormat:@""];
[serializedForm appendFormat:message];
[serializedForm appendFormat:@"
\n"];

[serializedForm appendFormat:@""];
[serializedForm appendFormat:locale];
[serializedForm appendFormat:@"
"];


return serializedForm;
}
/* elements */
/* attributes */
- (NSDictionary *)attributes
{
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

return attributes;
}
+ (sendSms_SendSms *)deserializeNode:(xmlNodePtr)cur
{
sendSms_SendSms *newObject = [[sendSms_SendSms new] autorelease];

[newObject deserializeAttributesFromNode:cur];
[newObject deserializeElementsFromNode:cur];

return newObject;
}
- (void)deserializeAttributesFromNode:(xmlNodePtr)cur
{
}
- (void)deserializeElementsFromNode:(xmlNodePtr)cur
{


}
@end








@implementation sendSms_SendSmsResponse

@synthesize statusString;

- (id)init
{
if((self = [super init])) {
}

return self;
}
- (void)dealloc
{

[super dealloc];
}
- (NSString *)nsPrefix
{
return @"sendSms";
}
- (NSString *)serializedFormUsingElementName:(NSString *)elName
{
NSMutableString *serializedForm = [NSMutableString string];

[serializedForm appendFormat:@"<%@ xsi:type=\"sendSms:SendSmsResponse\"", elName];
[serializedForm appendString:[self serializedAttributeString]];
[serializedForm appendFormat:@">"];

[serializedForm appendString:[self serializedElementString]];

[serializedForm appendFormat:@"\n", elName];

return serializedForm;
}
- (NSString *)serializedAttributeString
{
NSMutableString *serializedForm = [NSMutableString string];



return serializedForm;
}
- (NSString *)serializedElementString
{
NSMutableString *serializedForm = [NSMutableString string];



return serializedForm;
}
/* elements */
/* attributes */
- (NSDictionary *)attributes
{
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

return attributes;
}
+ (sendSms_SendSmsResponse *)deserializeNode:(xmlNodePtr)cur
{
sendSms_SendSmsResponse *newObject = [[sendSms_SendSmsResponse new] autorelease];

[newObject deserializeAttributesFromNode:cur];
[newObject deserializeElementsFromNode:cur];

return newObject;
}
- (void)deserializeAttributesFromNode:(xmlNodePtr)cur
{
}
- (void)deserializeElementsFromNode:(xmlNodePtr)cur
{


if(xmlStrEqual(cur->name, (const xmlChar *) "SendSmsResponse")){

// In this case we have got the ok answer
statusString = @"SENT";

} else if (xmlStrEqual(cur->name, (const xmlChar *) "Fault")){

// Something is wrong
NSLog(@" bodyNode last prev last content in deserializeElementsFromNode %s", cur->last->prev->last->content);

NSString *tmp = [NSString stringWithFormat:@"%s", cur->last->prev->last->content ];

// Strip out the garbage
//NSString *tmp1 = [tmp substringToIndex:174];
//NSString *tmp2 = [tmp1 substringFromIndex:106];


// Strip out the garbage
NSString *tmp1 = [tmp substringToIndex:174];

NSLog(@" tmp1 %@", tmp1);

NSRange nsr = [tmp rangeOfString:@" at"];

// Remove trailer message after at
if (nsr.location < 174 ){

tmp1 = [tmp1 substringToIndex:nsr.location];

};

NSLog(@" tmp1 %@", tmp1);

NSString *tmp2 = [tmp1 substringFromIndex:106];

NSLog(@" tmp2 %@Ò", tmp2);

statusString = [[NSString alloc] initWithString:tmp2 ];

}

if (statusString == NULL){
statusString = @"UNDEFINED";
};

}
@end
@implementation sendSms
+ (void)initialize
{
[[USGlobals sharedInstance].wsdlStandardNamespaces setObject:@"xsd" forKey:@"http://www.w3.org/2001/XMLSchema"];
[[USGlobals sharedInstance].wsdlStandardNamespaces setObject:@"sendSms" forKey:@"http://FreebieSMS.co.uk"];
}
+ (sendSmsSoap *)sendSmsSoap
{
return [[[sendSmsSoap alloc] initWithAddress:@"http://www.freebiesms.co.uk/sendsms.asmx"] autorelease];
}
+ (sendSmsSoap12 *)sendSmsSoap12
{
return [[[sendSmsSoap12 alloc] initWithAddress:@"http://www.freebiesms.co.uk/sendsms.asmx"] autorelease];
}
@end
@implementation sendSmsSoap
@synthesize address;
@synthesize logXMLInOut;
- (id)init
{
if((self = [super init])) {
address = nil;
cookies = nil;
logXMLInOut = NO;
}

return self;
}
- (id)initWithAddress:(NSString *)anAddress
{
if((self = [self init])) {
self.address = [NSURL URLWithString:anAddress];
}

return self;
}
- (void)addCookie:(NSHTTPCookie *)toAdd
{
if(toAdd != nil) {
if(cookies == nil) cookies = [[NSMutableArray alloc] init];
[cookies addObject:toAdd];
}
}
- (sendSmsSoapResponse *)SendSmsUsingParameters:(sendSms_SendSms *)aParameters
{
sendSmsSoap_SendSms *operation = [(sendSmsSoap_SendSms*)[sendSmsSoap_SendSms alloc] initWithBinding:self
parameters:aParameters
];

NSOperationQueue *queue = [[NSOperationQueue new] autorelease];

[queue addOperation:operation];

[queue waitUntilAllOperationsAreFinished];

return operation.response;
}
- (NSString *)sendHTTPCallUsingBody:(NSString *)outputBody soapAction:(NSString *)soapAction
{
NSMutableDictionary *HTTPHeaders = [NSMutableDictionary dictionary];
if(cookies != nil) {
NSDictionary *fCookies = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
[HTTPHeaders addEntriesFromDictionary:fCookies];
}
[HTTPHeaders setObject:@"http://www.freebiesms.co.uk/sendsms.asmx HTTP/1.1" forKey:@"POST"];
[HTTPHeaders setObject:@"text/xml;charset=UTF-8" forKey:@"Content-Type"];
[HTTPHeaders setObject:soapAction forKey:@"SOAPAction"];
[HTTPHeaders setObject:@"wsdl2objc" forKey:@"User-Agent"];
[HTTPHeaders setObject:@"www.freebiesms.co.uk" forKey:@"Host"];
[HTTPHeaders setObject:@"641" forKey:@"Content-Length"];


CFHTTPMessageRef request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)@"POST", (CFURLRef)self.address, kCFHTTPVersion1_1);

CFDataRef bodyData = (CFDataRef)[outputBody dataUsingEncoding:NSUTF8StringEncoding];
CFHTTPMessageSetBody(request, bodyData);

for(NSString *key in [HTTPHeaders allKeys]) {
CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)key, (CFStringRef)[HTTPHeaders objectForKey:key]);
}

NSDictionary *outputHeaders = (NSDictionary*)CFHTTPMessageCopyAllHeaderFields(request);

if(self.logXMLInOut) {
NSLog(@"OutputHeaders:\n%@", outputHeaders);
NSLog(@"OutputBody:\n%@", outputBody);
}

CFReadStreamRef readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request);

if(!CFReadStreamOpen(readStream)) {
CFStreamError myErr = CFReadStreamGetError(readStream);
// An error has occurred.
if (myErr.domain == kCFStreamErrorDomainPOSIX) {
// Interpret myErr.error as a UNIX errno.
} else if (myErr.domain == kCFStreamErrorDomainMacOSStatus) {
// Interpret myErr.error as a MacOS error code.
//OSStatus macError = (OSStatus)myErr.error;
// Check other error domains.
}
}

CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);

//CFHTTPMessageRef resp = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
//NSString *statusLine = (NSString*)CFHTTPMessageCopyResponseStatusLine(resp);

//NSLog(@"status line %@",statusLine );

NSMutableString *responseBody = [NSMutableString string];

static unsigned int kReadBufSize = 1024;
CFIndex numBytesRead;
do {
UInt8 buf[kReadBufSize];
numBytesRead = CFReadStreamRead(readStream, buf, sizeof(buf));

if( numBytesRead > 0 ) {
[responseBody appendString:[[[NSString alloc] initWithBytes:buf length:numBytesRead encoding:NSUTF8StringEncoding] autorelease]];
} else if( numBytesRead < 0 ) {
CFStreamError error = CFReadStreamGetError(readStream);
//[[NSApplication sharedApplication] presentError:(NSError*)error];
NSLog(@"error %@", error);
}
//} while( numBytesRead > 0 );
sleep(1);
NSLog(@" rebelotte");
} while( numBytesRead < 1 );

CFHTTPMessageRef response = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
NSDictionary *responseHeaders = (NSDictionary*)CFHTTPMessageCopyAllHeaderFields(response);
[responseHeaders autorelease];

if(cookies) [cookies release];
cookies = [[NSHTTPCookie cookiesWithResponseHeaderFields:responseHeaders forURL:self.address] mutableCopy];

if(self.logXMLInOut) {
NSLog(@"ResponseHeaders:\n%@", responseHeaders);
NSLog(@"ResponseBody:\n%@", responseBody);
}

return responseBody;
}
@end
@implementation sendSmsSoap_SendSms
@synthesize binding;
@synthesize response;
@synthesize parameters;
- (id)initWithBinding:(sendSmsSoap *)aBinding
parameters:(sendSms_SendSms *)aParameters
{
if((self = [super init])) {
response = nil;

self.binding = aBinding;

self.parameters = aParameters;
}

return self;
}
- (void)dealloc
{
if(binding != nil) [binding release];
if(parameters != nil) [parameters release];

[super dealloc];
}
- (void)main
{
[response autorelease];
response = [sendSmsSoapResponse new];

sendSmsSoap_envelope *envelope = [sendSmsSoap_envelope sharedInstance];

NSMutableDictionary *headerElements = nil;
headerElements = [NSMutableDictionary dictionary];

NSMutableDictionary *bodyElements = nil;
bodyElements = [NSMutableDictionary dictionary];
if(parameters != nil) [bodyElements setObject:parameters forKey:@"SendSms"];

NSString *operationXMLString = [envelope serializedFormUsingHeaderElements:headerElements bodyElements:bodyElements];

NSLog(@" operationXMLString %@", operationXMLString);

NSString *responseBody = [binding sendHTTPCallUsingBody:operationXMLString soapAction:@"http://FreebieSMS.co.uk/SendSms"];

NSLog(@" sendSmsSoap_SendSms main responseBody %@", responseBody);

xmlDocPtr doc;
xmlNodePtr cur;

const char *buffer = [responseBody cStringUsingEncoding:NSUTF8StringEncoding];

doc = xmlParseMemory(buffer, [responseBody length]);

NSAssert(doc != NULL, @"Errors while parsing returned XML");

cur = xmlDocGetRootElement(doc);
cur = cur->children;

for( ; cur != NULL ; cur = cur->next) {
if(cur->type == XML_ELEMENT_NODE) {

if(xmlStrEqual(cur->name, (const xmlChar *) "Body")) {
NSMutableArray *responseBodyParts = [NSMutableArray array];

xmlNodePtr bodyNode;
for(bodyNode=cur->children ; bodyNode != NULL ; bodyNode = bodyNode->next) {
if(cur->type == XML_ELEMENT_NODE) {
if(xmlStrEqual(bodyNode->name, (const xmlChar *) "SendSmsResponse") || xmlStrEqual(bodyNode->name, (const xmlChar *) "Fault") ) {
sendSms_SendSmsResponse *bodyObject = [sendSms_SendSmsResponse deserializeNode:bodyNode];
NSAssert1(bodyObject != nil, @"Errors while parsing body %s", bodyNode->name);
[responseBodyParts addObject:bodyObject];

} else {

NSLog(@" xml str no SendSmsResponse nor Fault %s", bodyNode->name );
}
}
}

response.bodyParts = responseBodyParts;
}
}
}

xmlFreeDoc(doc);

xmlCleanupParser();
}
@end
static sendSmsSoap_envelope *sendSmsSoapSharedEnvelopeInstance = nil;
@implementation sendSmsSoap_envelope
+ (sendSmsSoap_envelope *)sharedInstance
{
if(sendSmsSoapSharedEnvelopeInstance == nil) {
sendSmsSoapSharedEnvelopeInstance = [sendSmsSoap_envelope new];
}

return sendSmsSoapSharedEnvelopeInstance;
}
- (NSString *)serializedFormUsingHeaderElements:(NSDictionary *)headerElements bodyElements:(NSDictionary *)bodyElements
{
NSMutableString *serializedForm = [NSMutableString string];

[serializedForm appendFormat:@"\n"];
[serializedForm appendFormat:@" [serializedForm appendFormat:@"xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xsl:version=\"1.0\"\n"];
[serializedForm appendFormat:@"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"];
[serializedForm appendFormat:@"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"];
[serializedForm appendFormat:@"xmlns:sendSms=\"http://FreebieSMS.co.uk\""];
[serializedForm appendFormat:@">\n"];

if(headerElements != nil) {
[serializedForm appendFormat:@"\n"];

for(NSString *key in [headerElements allKeys]) {
id header = [headerElements objectForKey:key];
NSString *elementName = [NSString stringWithFormat:@"%@:%@", [header nsPrefix], key];

[serializedForm appendFormat:@"%@\n", [header serializedFormUsingElementName:elementName]];
}

[serializedForm appendFormat:@"
"];
}

if(bodyElements != nil) {
[serializedForm appendFormat:@"\n"];

for(NSString *key in [bodyElements allKeys]) {
id body = [bodyElements objectForKey:key];
NSString *elementName = [NSString stringWithFormat:@"%@:%@", [body nsPrefix], key];

[serializedForm appendFormat:@"%@\n", [body serializedFormUsingElementName:elementName]];
}

[serializedForm appendFormat:@"
\n"];
}

[serializedForm appendFormat:@"
"];

return serializedForm;
}
@end
@implementation sendSmsSoapResponse
@synthesize headers;
@synthesize bodyParts;
- (id)init
{
if((self = [super init])) {
headers = nil;
bodyParts = nil;
}

return self;
}
@end
@implementation sendSmsSoap12
@synthesize address;
@synthesize logXMLInOut;
- (id)init
{
if((self = [super init])) {
address = nil;
cookies = nil;
logXMLInOut = NO;
}

return self;
}
- (id)initWithAddress:(NSString *)anAddress
{
if((self = [self init])) {
self.address = [NSURL URLWithString:anAddress];
}

return self;
}
- (void)addCookie:(NSHTTPCookie *)toAdd
{
if(toAdd != nil) {
if(cookies == nil) cookies = [[NSMutableArray alloc] init];
[cookies addObject:toAdd];
}
}
- (sendSmsSoap12Response *)SendSmsUsingParameters:(sendSms_SendSms *)aParameters
{
sendSmsSoap12_SendSms *operation = [(sendSmsSoap12_SendSms*)[sendSmsSoap12_SendSms alloc] initWithBinding:self
parameters:aParameters
];

NSOperationQueue *queue = [[NSOperationQueue new] autorelease];

[queue addOperation:operation];

[queue waitUntilAllOperationsAreFinished];

return operation.response;
}
- (NSString *)sendHTTPCallUsingBody:(NSString *)outputBody soapAction:(NSString *)soapAction
{
NSMutableDictionary *HTTPHeaders = [NSMutableDictionary dictionary];
if(cookies != nil) {
NSDictionary *fCookies = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
[HTTPHeaders addEntriesFromDictionary:fCookies];
}
[HTTPHeaders setObject:@"wsdl2objc" forKey:@"UserAgent"];
[HTTPHeaders setObject:soapAction forKey:@"SOAPAction"];

CFHTTPMessageRef request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)@"POST", (CFURLRef)self.address, kCFHTTPVersion1_1);

CFDataRef bodyData = (CFDataRef)[outputBody dataUsingEncoding:NSUTF8StringEncoding];
CFHTTPMessageSetBody(request, bodyData);

for(NSString *key in [HTTPHeaders allKeys]) {
CFHTTPMessageSetHeaderFieldValue(request, (CFStringRef)key, (CFStringRef)[HTTPHeaders objectForKey:key]);
}

NSDictionary *outputHeaders = (NSDictionary*)CFHTTPMessageCopyAllHeaderFields(request);

if(self.logXMLInOut) {
NSLog(@"OutputHeaders:\n%@", outputHeaders);
NSLog(@"OutputBody:\n%@", outputBody);
}

CFReadStreamRef readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request);

if(!CFReadStreamOpen(readStream)) {
CFStreamError myErr = CFReadStreamGetError(readStream);
// An error has occurred.
if (myErr.domain == kCFStreamErrorDomainPOSIX) {
// Interpret myErr.error as a UNIX errno.
} else if (myErr.domain == kCFStreamErrorDomainMacOSStatus) {
// Interpret myErr.error as a MacOS error code.
//OSStatus macError = (OSStatus)myErr.error;
// Check other error domains.
}
}

CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue);

//CFHTTPMessageRef response = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
//NSString *statusLine = (NSString*)CFHTTPMessageCopyResponseStatusLine(response);

NSMutableString *responseBody = [NSMutableString string];

static unsigned int kReadBufSize = 1024;
CFIndex numBytesRead;
do {
UInt8 buf[kReadBufSize];
numBytesRead = CFReadStreamRead(readStream, buf, sizeof(buf));
if( numBytesRead > 0 ) {
[responseBody appendString:[[[NSString alloc] initWithBytes:buf length:numBytesRead encoding:NSUTF8StringEncoding] autorelease]];
} else if( numBytesRead < 0 ) {
//CFStreamError error = CFReadStreamGetError(readStream);
//[[NSApplication sharedApplication] presentError:(NSError*)error];
}
} while( numBytesRead > 0 );

CFHTTPMessageRef response = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
NSDictionary *responseHeaders = (NSDictionary*)CFHTTPMessageCopyAllHeaderFields(response);
[responseHeaders autorelease];

if(cookies) [cookies release];
cookies = [[NSHTTPCookie cookiesWithResponseHeaderFields:responseHeaders forURL:self.address] mutableCopy];

if(self.logXMLInOut) {
NSLog(@"ResponseHeaders:\n%@", responseHeaders);
NSLog(@"ResponseBody:\n%@", responseBody);
}

return responseBody;
}
@end
@implementation sendSmsSoap12_SendSms
@synthesize binding;
@synthesize response;
@synthesize parameters;
- (id)initWithBinding:(sendSmsSoap12 *)aBinding
parameters:(sendSms_SendSms *)aParameters
{
if((self = [super init])) {
response = nil;

self.binding = aBinding;

self.parameters = aParameters;
}

return self;
}
- (void)dealloc
{
if(binding != nil) [binding release];
if(parameters != nil) [parameters release];

[super dealloc];
}
- (void)main
{
[response autorelease];
response = [sendSmsSoap12Response new];

sendSmsSoap12_envelope *envelope = [sendSmsSoap12_envelope sharedInstance];

NSMutableDictionary *headerElements = nil;
headerElements = [NSMutableDictionary dictionary];

NSMutableDictionary *bodyElements = nil;
bodyElements = [NSMutableDictionary dictionary];
if(parameters != nil) [bodyElements setObject:parameters forKey:@"SendSms"];

NSString *operationXMLString = [envelope serializedFormUsingHeaderElements:headerElements bodyElements:bodyElements];

NSString *responseBody = [binding sendHTTPCallUsingBody:operationXMLString soapAction:@"http://FreebieSMS.co.uk/SendSms"];

xmlDocPtr doc;
xmlNodePtr cur;

const char *buffer = [responseBody cStringUsingEncoding:NSUTF8StringEncoding];

doc = xmlParseMemory(buffer, [responseBody length]);

NSAssert(doc != NULL, @"Errors while parsing returned XML");

cur = xmlDocGetRootElement(doc);
cur = cur->children;

for( ; cur != NULL ; cur = cur->next) {
if(cur->type == XML_ELEMENT_NODE) {

if(xmlStrEqual(cur->name, (const xmlChar *) "Body")) {
NSMutableArray *responseBodyParts = [NSMutableArray array];

xmlNodePtr bodyNode;
for(bodyNode=cur->children ; bodyNode != NULL ; bodyNode = bodyNode->next) {
if(cur->type == XML_ELEMENT_NODE) {
if(xmlStrEqual(bodyNode->name, (const xmlChar *) "SendSmsResponse")) {
sendSms_SendSmsResponse *bodyObject = [sendSms_SendSmsResponse deserializeNode:bodyNode];
NSAssert1(bodyObject != nil, @"Errors while parsing body %s", bodyNode->name);
[responseBodyParts addObject:bodyObject];
}
}
}

response.bodyParts = responseBodyParts;
}
}
}

xmlFreeDoc(doc);

xmlCleanupParser();
}
@end
static sendSmsSoap12_envelope *sendSmsSoap12SharedEnvelopeInstance = nil;
@implementation sendSmsSoap12_envelope
+ (sendSmsSoap12_envelope *)sharedInstance
{
if(sendSmsSoap12SharedEnvelopeInstance == nil) {
sendSmsSoap12SharedEnvelopeInstance = [sendSmsSoap12_envelope new];
}

return sendSmsSoap12SharedEnvelopeInstance;
}
- (NSString *)serializedFormUsingHeaderElements:(NSDictionary *)headerElements bodyElements:(NSDictionary *)bodyElements
{
NSMutableString *serializedForm = [NSMutableString string];

[serializedForm appendFormat:@"\n"];
[serializedForm appendFormat:@" [serializedForm appendFormat:@"xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xsl:version=\"1.0\"\n"];
[serializedForm appendFormat:@"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"];
[serializedForm appendFormat:@"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"];
[serializedForm appendFormat:@"xmlns:sendSms=\"http://FreebieSMS.co.uk\"\n"];
[serializedForm appendFormat:@">\n"];

if(headerElements != nil) {
[serializedForm appendFormat:@"\n"];

for(NSString *key in [headerElements allKeys]) {
id header = [headerElements objectForKey:key];
NSString *elementName = [NSString stringWithFormat:@"%@:%@", [header nsPrefix], key];

[serializedForm appendFormat:@"%@\n", [header serializedFormUsingElementName:elementName]];
}

[serializedForm appendFormat:@"
"];
}

if(bodyElements != nil) {
[serializedForm appendFormat:@"\n"];

for(NSString *key in [bodyElements allKeys]) {
id body = [bodyElements objectForKey:key];
NSString *elementName = [NSString stringWithFormat:@"%@:%@", [body nsPrefix], key];

[serializedForm appendFormat:@"%@\n", [body serializedFormUsingElementName:elementName]];
}

[serializedForm appendFormat:@"
\n"];
}

[serializedForm appendFormat:@"
"];

return serializedForm;
}
@end
@implementation sendSmsSoap12Response
@synthesize headers;
@synthesize bodyParts;
- (id)init
{
if((self = [super init])) {
headers = nil;
bodyParts = nil;
}

return self;
}
@end

No comments: