📄 service.cpp
字号:
// the code below is a hack around the RPC encoded response message element tag mismatch with Axis: if (!output_body->namespace_ || output_body->use == encoded) o->output->URI = o->input->URI; // encoded seems (?) to require the request's namespace else o->output->URI = output_body->namespace_; o->output->encodingStyle = output_body->encodingStyle; o->output->message = output->messagePtr(); o->output->part = NULL; o->output->multipartRelated = ext_output->mime__multipartRelated_; o->output->content = NULL; if (ext_output->mime__multipartRelated_ && !ext_output->mime__multipartRelated_->part.empty()) o->output->header = ext_output->mime__multipartRelated_->part.front().soap__header_; else o->output->header = ext_output->soap__header_; if (ext_output->mime__multipartRelated_ && !ext_output->mime__multipartRelated_->part.empty() && ext_output->mime__multipartRelated_->part.front().soap__body_) o->output->body_parts = ext_output->mime__multipartRelated_->part.front().soap__body_->parts; else o->output->body_parts = output_body->parts; if (ext_output->dime__message_) o->output->layout = ext_output->dime__message_->layout; else o->output->layout = NULL; o->output->documentation = output->documentation; o->output->ext_documentation = ext_output->documentation; char *s = (char*)soap_malloc(definitions.soap, strlen(o->output->name) + 9); strcpy(s, o->output->name); strcat(s, "Response"); if (soap__operation_style == document) o->output_name = types.oname("__", o->URI, s); else o->output_name = types.oname(NULL, o->output->URI, s); } } else { o->output_name = NULL; o->output = NULL; } // collect input headers and headerfaults if (ext_input) { const vector<soap__header> *soap__header_ = NULL; // check if soap header is in mime:multipartRelated if (ext_input->mime__multipartRelated_) { for (vector<mime__part>::const_iterator part = ext_input->mime__multipartRelated_->part.begin(); part != ext_input->mime__multipartRelated_->part.end(); ++part) if (!(*part).soap__header_.empty()) { soap__header_ = &(*part).soap__header_; break; } } if (!soap__header_) soap__header_ = &ext_input->soap__header_; for (vector<soap__header>::const_iterator header = soap__header_->begin(); header != soap__header_->end(); ++header) { Message *h = new Message(); h->message = (*header).messagePtr(); h->body_parts = NULL; h->part = (*header).partPtr(); h->URI = (*header).namespace_; if (h->part && h->part->element) h->name = types.aname(NULL, NULL, h->part->element); else if (h->URI && h->part && h->part->name && h->part->type) h->name = types.aname(NULL, h->URI, h->part->name); else { fprintf(stderr, "Error in SOAP Header part definition: input part '%s' missing?\n", h->part && h->part->name ? h->part->name : "?"); h->name = ""; } h->encodingStyle = (*header).encodingStyle; h->use = (*header).use; h->multipartRelated = NULL; h->content = NULL; h->layout = NULL; h->ext_documentation = NULL; // TODO: add document content h->documentation = NULL; // TODO: add document content s->header[h->name] = h; for (vector<soap__headerfault>::const_iterator headerfault = (*header).headerfault.begin(); headerfault != (*header).headerfault.end(); ++headerfault) { // TODO: complete headerfault processing. This is rarely used. } } } // collect output headers and headerfaults if (ext_output) { const vector<soap__header> *soap__header_ = NULL; // check if soap header is in mime:multipartRelated if (ext_output->mime__multipartRelated_) { for (vector<mime__part>::const_iterator part = ext_output->mime__multipartRelated_->part.begin(); part != ext_output->mime__multipartRelated_->part.end(); ++part) if (!(*part).soap__header_.empty()) { soap__header_ = &(*part).soap__header_; break; } } if (!soap__header_) soap__header_ = &ext_output->soap__header_; for (vector<soap__header>::const_iterator header = soap__header_->begin(); header != soap__header_->end(); ++header) { Message *h = new Message(); h->message = (*header).messagePtr(); h->body_parts = NULL; h->part = (*header).partPtr(); h->URI = (*header).namespace_; if (h->part && h->part->element) h->name = types.aname(NULL, NULL, h->part->element); else if (h->URI && h->part && h->part->name && h->part->type) h->name = types.aname(NULL, h->URI, h->part->name); else { fprintf(stderr, "Error in SOAP Header part definition: output part '%s' missing?\n", h->part && h->part->name ? h->part->name : "?"); h->name = ""; } h->encodingStyle = (*header).encodingStyle; h->use = (*header).use; h->multipartRelated = NULL; h->content = NULL; h->layout = NULL; h->ext_documentation = NULL; // TODO: add document content h->documentation = NULL; // TODO: add document content s->header[h->name] = h; for (vector<soap__headerfault>::const_iterator headerfault = (*header).headerfault.begin(); headerfault != (*header).headerfault.end(); ++headerfault) { // TODO: complete headerfault processing. This is rarely used. } } } // collect faults for (vector<wsdl__ext_fault>::const_iterator ext_fault = (*operation).fault.begin(); ext_fault != (*operation).fault.end(); ++ext_fault) { if ((*ext_fault).soap__fault_ && (*ext_fault).messagePtr()) { Message *f = new Message(); f->message = (*ext_fault).messagePtr(); f->body_parts = NULL; f->part = NULL; f->encodingStyle = (*ext_fault).soap__fault_->encodingStyle; f->URI = (*ext_fault).soap__fault_->namespace_; f->use = (*ext_fault).soap__fault_->use; if (f->use == literal && !f->URI) f->URI = s->URI; // must have a unique URI f->multipartRelated = NULL; f->content = NULL; f->layout = NULL; f->ext_documentation = (*ext_fault).documentation; f->name = types.aname("_", f->URI, f->message->name); f->documentation = f->message->documentation; o->fault.push_back(f); s->fault[f->name] = f; } else fprintf(stderr, "Error: no wsdl:definitions/binding/operation/fault/soap:fault\n"); } s->operation.push_back(o); } else fprintf(stderr, "Warning: no SOAP RPC operation namespace, operations will be ignored\n"); } else fprintf(stderr, "Error: no wsdl:definitions/binding/operation/input/soap:body\n"); } else fprintf(stderr, "Error: no wsdl:definitions/portType/operation/input\n"); } else fprintf(stderr, "Error: no wsdl:definitions/portType/operation\n"); } }}void Definitions::compile(const wsdl__definitions& definitions){ // compile the definitions and generate gSOAP header file const char *defs; if (definitions.name) defs = types.aname(NULL, NULL, definitions.name); else defs = "Service"; ident(); fprintf(stream, "/* NOTE:\n\n - Compile this file with soapcpp2 to complete the code generation process.\n - Use soapcpp2 option -I to specify paths for #import\n To build with STL, 'stlvector.h' is imported from 'import' dir in package.\n - Use wsdl2h options -c and -s to generate pure C code or C++ code without STL.\n - Use 'typemap.dat' to control schema namespace bindings and type mappings.\n It is strongly recommended to customize the names of the namespace prefixes\n generated by wsdl2h. To do so, modify the prefix bindings in the Namespaces\n section below and add the modified lines to 'typemap.dat' to rerun wsdl2h.\n - Use Doxygen (www.doxygen.org) to browse this file.\n - Use wsdl2h option -l to view the software license terms.\n\n DO NOT include this file directly into your project.\n Include only the soapcpp2-generated headers and source code files.\n*/\n"); // gsoap compiler options: 'w' disables WSDL/schema output to avoid file collisions if (cflag) fprintf(stream, "\n//gsoapopt cw\n"); else fprintf(stream, "\n//gsoapopt w\n"); banner(definitions.targetNamespace?definitions.targetNamespace:"targetNamespace"); // copy documentation from WSDL definitions if (definitions.documentation) { fprintf(stream, "/* WSDL Documentation:\n\n"); text(definitions.documentation); fprintf(stream, "*/\n\n"); } if (lflag) { banner("License"); fprintf(stream, "/*\n%s*/\n\n", licensenotice); } if (definitions.version) { banner("Version"); fprintf(stream, "#define SOAP_WSDL_VERSION \"%s\"\n", definitions.version); } banner("Import"); if (dflag) { fprintf(stream, "\n// dom.h declares the DOM xsd__anyType object (compiler and link with dom.cpp)\n"); if (import_path) fprintf(stream, "#import \"%s/dom.h\"\n", import_path); else fprintf(stream, "#import \"dom.h\"\n"); } if (!cflag && !sflag) { fprintf(stream, "\n// STL vector containers (use option -s to disable)\n"); if (import_path) fprintf(stream, "#import \"%s/stlvector.h\"\n", import_path); else fprintf(stream, "#import \"stlvector.h\"\n"); } if (mflag) { if (import_path) fprintf(stream, "#import \"%s/", import_path); else fprintf(stream, "#import \""); fprintf(stream, "xsd.h\"\t// import primitive XSD types.\n"); } for (SetOfString::const_iterator u = exturis.begin(); u != exturis.end(); ++u) { bool found = false; size_t n = strlen(*u); for (SetOfString::const_iterator i = definitions.builtinTypes().begin(); i != definitions.builtinTypes().end(); ++i) { if (**i == '"' && !strncmp(*u, *i + 1, n)) { found = true; break; } } if (!found) { for (SetOfString::const_iterator j = definitions.builtinElements().begin(); j != definitions.builtinElements().end(); ++j) { if (**j == '"' && !strncmp(*u, *j + 1, n)) { found = true; break; } } } if (!found) { for (SetOfString::const_iterator k = definitions.builtinAttributes().begin(); k != definitions.builtinAttributes().end(); ++k) { if (**k == '"' && !strncmp(*u, *k + 1, n)) { found = true; break; } } } if (found) { if (vflag) fprintf(stderr, "import %s\n", *u); if (import_path) fprintf(stream, "#import \"%s/%s.h\"\t// %s = <%s>\n", import_path, types.nsprefix(NULL, *u), types.nsprefix(NULL, *u), *u); else fprintf(stream, "#import \"%s.h\"\t// %s = <%s>\n", types.nsprefix(NULL, *u), types.nsprefix(NULL, *u), *u); } } banner("Schema Namespaces"); // determine if we must use SOAP 1.2, this is a bit of a hack due to the lack of WSDL1.1/SOAP1.2 support and better alternatives for (Namespace *p = definitions.soap->local_namespaces; p && p->id; p++) { // p->out is set to the actual namespace name that matches the p->in pattern if (p->out && !strcmp(p->id, "soap") && !strcmp(p->out, "http://schemas.xmlsoap.org/wsdl/soap12/")) { fprintf(stream, "// This service uses SOAP 1.2 namespaces:\n"); fprintf(stream, schemaformat, "SOAP-ENV", "namespace", "http://www.w3.org/2003/05/soap-envelope"); fprintf(stream, schemaformat, "SOAP-ENC", "namespace", "http://www.w3.org/2003/05/soap-encoding"); break; } } if (definitions.types) { fprintf(stream, "\n/* NOTE:\n\nIt is strongly recommended to customize the names of the namespace prefixes\ngenerated by wsdl2h. To do so, modify the prefix bindings below and add the\nmodified lines to typemap.dat to rerun wsdl2h:\n\n"); if (definitions.targetNamespace && *definitions.targetNamespace) fprintf(stream, "%s = \"%s\"\n", types.nsprefix(service_prefix, definitions.targetNamespace), definitions.targetNamespace);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -