• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

            路漫漫,長修遠,我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
            數(shù)據(jù)加載中……

            IOS WSDL2OBJC如何與CXF對接

            首先, WSDL2OBJC直接生成的代碼是無法正確發(fā)送CXF能解析的數(shù)據(jù)包的

            我懶得去看WSDL2OBJC的源碼, 但是由其生成的源碼看看倒是ok的

            我wsdl的服務名是HotelPortService
            生成的文件中有個HotelPortServiceSvc.m, 要修改的地方全部集中在這個文件
            首先, 找到如下代碼的位置, 替換掉

            - (NSString *)serializedFormUsingHeaderElements:(NSDictionary *)headerElements bodyElements:(NSDictionary *)bodyElements

            {

                xmlDocPtr doc;

            doc = xmlNewDoc((const xmlChar*)XML_DEFAULT_VERSION);

            if (doc == NULL) {

            NSLog(@"Error creating the xml document tree");

            return @"";

            }

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

            xmlDocSetRootElement(doc, root);

            xmlNsPtr soapEnvelopeNs = xmlNewNs(root, (const xmlChar*)"http://schemas.xmlsoap.org/soap/envelope/", (const xmlChar*)"soap");

            xmlSetNs(root, soapEnvelopeNs);

            xmlNsPtr xslNs = xmlNewNs(root, (const xmlChar*)"http://www.w3.org/1999/XSL/Transform", (const xmlChar*)"xsl");

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

            xmlNewNsProp(root, xslNs, (const xmlChar*)"version", (const xmlChar*)"1.0");

            xmlNewNs(root, (const xmlChar*)"http://www.w3.org/2001/XMLSchema", (const xmlChar*)"xs");

            xmlNewNs(root, (const xmlChar*)"http://port.ekezhan.com/", (const xmlChar*)"HotelPortServiceSvc");//字符串部分根據(jù)服務名不同而不同

            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 elementNSPrefix:nil]);

            }

            }

            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 elementNSPrefix:nil]);

            }

            }

            xmlChar *buf;

            int size;

            xmlDocDumpFormatMemory(doc, &buf, &size, 1);

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

            xmlFree(buf);

            xmlFreeDoc(doc);

            return serializedForm;

            }


            替換成:

            - (NSString *)serializedFormUsingHeaderElements:(NSDictionary *)headerElements bodyElements:(NSDictionary *)bodyElements

            {

                xmlDocPtr doc;

            doc = xmlNewDoc((const xmlChar*)XML_DEFAULT_VERSION);

            if (doc == NULL) {

            NSLog(@"Error creating the xml document tree");

            return @"";

            }

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

            xmlDocSetRootElement(doc, root);

            xmlNsPtr soapEnvelopeNs = xmlNewNs(root, (const xmlChar*)"http://schemas.xmlsoap.org/soap/envelope/", (const xmlChar*)"soapenv");//此處修改

            xmlSetNs(root, soapEnvelopeNs);

            //xmlNsPtr xslNs = xmlNewNs(root, (const xmlChar*)"http://www.w3.org/1999/XSL/Transform", (const xmlChar*)"xsl");

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

            //xmlNewNsProp(root, xslNs, (const xmlChar*)"version", (const xmlChar*)"1.0");

            //xmlNewNs(root, (const xmlChar*)"http://www.w3.org/2001/XMLSchema", (const xmlChar*)"xs");

                

            xmlNewNs(root, (const xmlChar*)"http://port.ekezhan.com/", (const xmlChar*)"port");

            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 elementNSPrefix:nil]);

            }

            }

            //此處修改

            else

            {  

            xmlNodePtr headerNode = xmlNewDocNode(doc, soapEnvelopeNs, (const xmlChar*)"Header", NULL);

            xmlAddChild(root, headerNode);

            }

            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 elementNSPrefix:@"port"]);//此處修改

            }

            }

            xmlChar *buf;

            int size;

            xmlDocDumpFormatMemory(doc, &buf, &size, 1);

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

            xmlFree(buf);

            xmlFreeDoc(doc);

            return serializedForm;

            }


            替換全部

            elementNSPrefix:@"HotelPortServiceSvc" 

            elementNSPrefix:nil  //字符串部分根據(jù)服務名不同而不同



            替換全部

            nodeName = [NSString stringWithFormat:@"%@:%@", @"HotelPortServiceSvc", elName];//字符串部分根據(jù)服務名不同而不同

             

            nodeName = [NSString stringWithFormat:@"%@", elName];




            然后再編譯運行. 如果沒有意外, 就能獲得正確的結(jié)果了. 文檔如有錯漏, 歡迎指正補全



            測試環(huán)境 

            Mac OS 10.6.8,  xcode 4.0.1,  WSDL2ObjC 0.7 pre1

            posted on 2011-11-04 17:36 Khan 閱讀(1772) 評論(2)  編輯 收藏 引用 所屬分類: 跨平臺開發(fā)

            評論

            # re: IOS WSDL2OBJC如何與CXF對接  回復  更多評論   

            比較討厭d地方是, 每次發(fā)布的webservice變動. 都需要重復一次, 不過仍舊比人肉解析xml要省事兒
            2011-11-04 17:41 | Khan's Notebook

            # re: IOS WSDL2OBJC如何與CXF對接  回復  更多評論   

            我只想說太給力了。。解決了我一周都沒有解決的問題,webservice交互問題,忙了一周多都沒忙出來。。給力
            2014-09-11 14:59 | 左凌風
            奇米影视7777久久精品人人爽| 国产亚洲色婷婷久久99精品| 亚洲国产精品婷婷久久| 伊人久久大香线蕉影院95| 久久一区二区三区免费| 亚洲精品国产字幕久久不卡| 国产成人精品久久亚洲高清不卡| 久久久久国产视频电影| 久久精品无码一区二区无码| 久久精品无码专区免费| 人妻无码中文久久久久专区| 久久精品无码专区免费| 久久国产精品久久国产精品| 亚洲欧美成人久久综合中文网| 久久精品国产精品青草app| 久久www免费人成看片| 久久精品这里只有精99品| 99re这里只有精品热久久| 伊人久久五月天| 嫩草影院久久国产精品| 亚洲国产精品成人久久| 亚洲欧美日韩精品久久亚洲区| 99精品久久精品| 久久99精品久久久久久动态图| 国产精品久久久久久久人人看| 久久天天日天天操综合伊人av| 午夜不卡888久久| 久久91精品久久91综合| 久久国产精品77777| 日本欧美久久久久免费播放网| 精品久久久久久无码不卡| 久久丝袜精品中文字幕| 欧美久久一区二区三区| 久久九色综合九色99伊人| 93精91精品国产综合久久香蕉| 99久久免费国产特黄| 久久99精品国产| 91精品国产综合久久四虎久久无码一级 | 久久久久亚洲精品男人的天堂 | 久久久久人妻一区二区三区 | 精品国产青草久久久久福利|