Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. calling a web service at runtime

calling a web service at runtime

Scheduled Pinned Locked Moved C#
questioncsharpwcfhelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus Spitzmiller
    wrote on last edited by
    #1

    Hey there, everyone. I'm a long time member, but my responsibilities don't get me into code too often...so, please go easy on me :-D I'm using .Net 4.0, WCF and my goal is to call a webservice - one that is not known at compile time. Now I know that during development, I can right click > Add Service Reference, but that's not what I'm looking for..again the web service won't be known at compile time. So, I've made it as far as to dynamically call a webservice and import all its contracts via the code below (taken from MSDN). And from that I can see all the different web service methods that are available in my webservice (in the string sWSDL at the very top). My question, then: How can I call this web service? I understand the definition, but I don't understand how to invoke it. Any help would be much appreciated.

    MetadataExchangeClient mexClient = new MetadataExchangeClient(new Uri(sWSDL), MetadataExchangeClientMode.HttpGet);
    mexClient.ResolveMetadataReferences = true;
    MetadataSet metaDocs = mexClient.GetMetadata();

            WsdlImporter importer = new WsdlImporter(metaDocs);
            ServiceContractGenerator generator = new ServiceContractGenerator();
    
            // Add our custom DCAnnotationSurrogate 
            // to write XSD annotations into the comments.
            object dataContractImporter;
            XsdDataContractImporter xsdDCImporter;
            if (!importer.State.TryGetValue(typeof(XsdDataContractImporter), out dataContractImporter))
            {
                Console.WriteLine("Couldn't find the XsdDataContractImporter! Adding custom importer.");
                xsdDCImporter = new XsdDataContractImporter();
                xsdDCImporter.Options = new ImportOptions();
                importer.State.Add(typeof(XsdDataContractImporter), xsdDCImporter);
            }
            else
            {
                xsdDCImporter = (XsdDataContractImporter)dataContractImporter;
                if (xsdDCImporter.Options == null)
                {
                    Console.WriteLine("There were no ImportOptions on the importer.");
                    xsdDCImporter.Options = new ImportOptions();
                }
            }
            
            //xsdDCImporter.Options.DataContractSurrogate = new DCAnnotationSurrogate();????
    
            // Uncomment the following code if you are going to do your work programmatically rather than add 
            // the WsdlDocumentationImporters through a configuration
    
    P 1 Reply Last reply
    0
    • M Marcus Spitzmiller

      Hey there, everyone. I'm a long time member, but my responsibilities don't get me into code too often...so, please go easy on me :-D I'm using .Net 4.0, WCF and my goal is to call a webservice - one that is not known at compile time. Now I know that during development, I can right click > Add Service Reference, but that's not what I'm looking for..again the web service won't be known at compile time. So, I've made it as far as to dynamically call a webservice and import all its contracts via the code below (taken from MSDN). And from that I can see all the different web service methods that are available in my webservice (in the string sWSDL at the very top). My question, then: How can I call this web service? I understand the definition, but I don't understand how to invoke it. Any help would be much appreciated.

      MetadataExchangeClient mexClient = new MetadataExchangeClient(new Uri(sWSDL), MetadataExchangeClientMode.HttpGet);
      mexClient.ResolveMetadataReferences = true;
      MetadataSet metaDocs = mexClient.GetMetadata();

              WsdlImporter importer = new WsdlImporter(metaDocs);
              ServiceContractGenerator generator = new ServiceContractGenerator();
      
              // Add our custom DCAnnotationSurrogate 
              // to write XSD annotations into the comments.
              object dataContractImporter;
              XsdDataContractImporter xsdDCImporter;
              if (!importer.State.TryGetValue(typeof(XsdDataContractImporter), out dataContractImporter))
              {
                  Console.WriteLine("Couldn't find the XsdDataContractImporter! Adding custom importer.");
                  xsdDCImporter = new XsdDataContractImporter();
                  xsdDCImporter.Options = new ImportOptions();
                  importer.State.Add(typeof(XsdDataContractImporter), xsdDCImporter);
              }
              else
              {
                  xsdDCImporter = (XsdDataContractImporter)dataContractImporter;
                  if (xsdDCImporter.Options == null)
                  {
                      Console.WriteLine("There were no ImportOptions on the importer.");
                      xsdDCImporter.Options = new ImportOptions();
                  }
              }
              
              //xsdDCImporter.Options.DataContractSurrogate = new DCAnnotationSurrogate();????
      
              // Uncomment the following code if you are going to do your work programmatically rather than add 
              // the WsdlDocumentationImporters through a configuration
      
      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You might find this article[^] useful in helping to call the service.

      I'm not a stalker, I just know things. Oh by the way, you're out of milk.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups