RWMostert / wsdl2objc

Automatically exported from code.google.com/p/wsdl2objc
MIT License
0 stars 0 forks source link

modify source to work with a NET SOAP 1.2 mthod #66

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

I modified this code in the iPhoneSvc to make the generated code work with a 
.NET SOAP 1.2 
method.

REWRITTEN VERSIONS -- FOR SOAP12 ONLY!!

- (NSString *)serializedFormUsingHeaderElements:(NSDictionary *)headerElements 
bodyElements:(NSDictionary *)bodyElements
{
    xmlDocPtr doc;
    int i = doc->type;

    if (i = XML_DOCUMENT_NODE)
        NSLog (@"xml doc node");

    doc = xmlNewDoc((const xmlChar*)XML_DEFAULT_VERSION);
    if (doc == NULL) {
        NSLog(@"Error creating the xml document tree");
        return @"";
    }

    doc->encoding = (const xmlChar*) "utf-8";

    xmlNodePtr root = xmlNewDocNode(doc, NULL, (const xmlChar*)"Envelope", NULL);
    xmlDocSetRootElement(doc, root);

    xmlNsPtr soapEnvelopeNs = xmlNewNs(root, (const 
xmlChar*)"http://www.w3.org/2003/05/soap-envelope", (const xmlChar*)"soap12");
    xmlSetNs(root, soapEnvelopeNs);

    xmlNsPtr xslNs = xmlNewNs(root, (const xmlChar*)"http://www.w3.org/2001/XMLSchema-
instance", (const xmlChar*)"xsi");
    xmlNewNs(root, (const xmlChar*)"http://www.w3.org/2001/XMLSchema", (const 
xmlChar*)"xsd");

    if((headerElements != nil) && ([headerElements count] > 0)) {
        xmlNodePtr headerNode = xmlNewDocNode(doc, soapEnvelopeNs, (const 
xmlChar*)"Header", NULL);
        xmlAddChild(root, headerNode);

        for(NSString *key in [headerElements allKeys]) {
            id header = [headerElements objectForKey:key];
            xmlAddChild(headerNode, [header xmlNodeForDoc:doc elementName:key]);
        }
    }

    if((bodyElements != nil) && ([bodyElements count] > 0)) {
        xmlNodePtr bodyNode = xmlNewDocNode(doc, soapEnvelopeNs, (const xmlChar*)"Body", 
NULL);
        xmlAddChild(root, bodyNode);

        for(NSString *key in [bodyElements allKeys]) {
            id body = [bodyElements objectForKey:key];
            xmlAddChild(bodyNode, [body xmlNodeForDoc:doc elementName:key]);
        }
    }

    xmlChar *buf;
    int size;
    xmlDocDumpFormatMemory(doc, &buf, &size, 1);

    NSString *serializedForm = [NSString stringWithCString:(const char*)buf 
encoding:NSUTF8StringEncoding];
    xmlFree(buf);

    //   if (doc)
    //       xmlFreeDoc(doc);   
    return serializedForm;
}
@end
=======================

- (void)sendHTTPCallUsingBody:(NSString *)outputBody soapAction:(NSString 
*)soapAction 
forOperation:(iphoneSoap12Operation *)operation
{
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.address 

cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                                       timeoutInterval:self.defaultTimeout];

    NSData *bodyData = [outputBody dataUsingEncoding:NSUTF8StringEncoding];

    if(cookies != nil) {
        [request setAllHTTPHeaderFields:[NSHTTPCookie 
requestHeaderFieldsWithCookies:cookies]];
    }
    [request setValue:@"Your Company" forHTTPHeaderField:@"User-Agent"];
    [request setValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-
Type"];
    [request setValue:[NSString stringWithFormat:@"%u", [bodyData length]] 
forHTTPHeaderField:@"Content-Length"];
    [request setValue:self.address.host forHTTPHeaderField:@"Host"];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: bodyData];

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

    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request 
delegate:operation];

    operation.urlConnection = connection;
    [connection release];
}

=======================

- (xmlNodePtr)xmlNodeForDoc:(xmlDocPtr)doc elementName:(NSString *)elName
{
    xmlNodePtr root = xmlDocGetRootElement(doc);

    xmlNodePtr node = xmlNewDocNode(doc, NULL, (const xmlChar*)[elName UTF8String], 
NULL);
    xmlSetNsProp(node, xmlns, (const xmlChar*)"xmlns", (const 
xmlChar*)"http://www.xxx.com/generator/iphone.asmx/");

    [self addAttributesToNode:node];

    [self addElementsToNode:node];

    return node;

END OF REWRITTEN VERSIONS

Original issue reported on code.google.com by michael....@gmail.com on 24 Dec 2009 at 9:44