c# - How does ServiceContractGenerator generate namespaces -


i trying use servicecontractgenerator generate web service client in c# wsdl. new class. using code pretty appears in example on microsoft's site , have read web. when run svcutil.exe on wsdl, types in same namespace in c# code. when use servicecontractgenerator, puts client code in namespace specify, creates second namespace wsdl types. wsdl has section this:

<wsdl:types><xsd:schema targetnamespace="http://tempuri.org/imports"><xsd:import schemalocation="http://devabntstapp10.psohealth.local/tz_tcs_services/adminservice.svc?xsd=xsd0" namespace="http://tempuri.org/"/><xsd:import schemalocation="http://yyy/zzz/adminservice.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/zzz.correspondence"/><xsd:import schemalocation="http:/yyy/zzz/adminservice.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/serialization/"/></xsd:schema></wsdl:types> 

there message defined

<wsdl:message name="icorrespondenceadmin_listowners_inputmessage"><wsdl:part name="parameters" element="tns:listowners"/></wsdl:message> 

the code using

   generator = new servicecontractgenerator();     try {         generator.namespacemappings.add("*", "webserviceclients");     }     catch (exception) {     }      metadataexchangeclient mexclient =         new metadataexchangeclient(             new uri(uri),             metadataexchangeclientmode.httpget);      mexclient.resolvemetadatareferences = true;     metadataset metadocs = mexclient.getmetadata();      wsdlimporter importer = new wsdlimporter(metadocs);      system.collections.objectmodel.collection<contractdescription> contracts       = importer.importallcontracts();     serviceendpointcollection eps = importer.importallendpoints();     foreach (contractdescription contract in contracts) {         generator.generateservicecontracttype(contract);     }       if (generator.errors.count != 0)         throw new exception("there errors during code compilation.");      stringwriter stringwriter =         new stringwriter(system.globalization.cultureinfo.currentculture);     system.codedom.compiler.indentedtextwriter textwriter         = new system.codedom.compiler.indentedtextwriter(stringwriter);      codedomprovider.generatecodefromcompileunit(         generator.targetcompileunit,         textwriter,         options);       textwriter.close(); 

i namespace of webservicesclients client class correspondenceadminclient , namespace of zzz.correspondence parameters , return types. svcutil puts them in webservicesclients. seem missing something.

you need redefine xmlimportoptions , xsddatacontracts, types not generated xsddatacontracts, guess generateservicecontract change namespace one.

        importer.state.remove(typeof(xsddatacontractimporter));         var xsddcimporter = new xsddatacontractimporter();         xsddcimporter.options = new importoptions();         xsddcimporter.options.namespaces.add("*", namespace);         importer.state.add(typeof(xsddatacontractimporter), xsddcimporter);          var xmloptions = new xmlserializerimportoptions(xsddcimporter.codecompileunit);         xmloptions.clrnamespace = namespace;         importer.state.add(typeof(xmlserializerimportoptions), xmloptions);          system.collections.objectmodel.collection<contractdescription> contracts = importer.importallcontracts(); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -