Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# and local SQL server connection Pin
JoplinsSlave21-Mar-11 23:57
JoplinsSlave21-Mar-11 23:57 
AnswerRe: C# and local SQL server connection Pin
Ravi Sant21-Mar-11 23:51
Ravi Sant21-Mar-11 23:51 
GeneralRe: C# and local SQL server connection Pin
JoplinsSlave22-Mar-11 0:04
JoplinsSlave22-Mar-11 0:04 
AnswerRe: C# and local SQL server connection Pin
Rob Philpott22-Mar-11 0:33
Rob Philpott22-Mar-11 0:33 
GeneralRe: C# and local SQL server connection Pin
Rob Philpott22-Mar-11 0:35
Rob Philpott22-Mar-11 0:35 
GeneralRe: C# and local SQL server connection Pin
Ravi Sant22-Mar-11 0:52
Ravi Sant22-Mar-11 0:52 
Questiondatagridview problems! Pin
King Boy21-Mar-11 19:54
King Boy21-Mar-11 19:54 
Questioncalling a web service at runtime Pin
Marcus Spitzmiller21-Mar-11 13:45
Marcus Spitzmiller21-Mar-11 13:45 
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 Big Grin | :-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 file. 
            
            // The following code inserts a custom WsdlImporter without removing the other 
            // importers already in the collection.
            System.Collections.Generic.IEnumerable<IWsdlImportExtension> exts = importer.WsdlImportExtensions;
            System.Collections.Generic.List<IWsdlImportExtension> newExts 
              = new System.Collections.Generic.List<IWsdlImportExtension>();
            foreach (IWsdlImportExtension ext in exts)
            {
              Console.WriteLine("Default WSDL import extensions: {0}", ext.GetType().Name);
              newExts.Add(ext);
            }
            //newExts.Add(new WsdlDocumentationImporter());
            System.Collections.Generic.IEnumerable<IPolicyImportExtension> polExts = importer.PolicyImportExtensions;
            importer = new WsdlImporter(metaDocs, polExts, newExts);
            

            System.Collections.ObjectModel.Collection<ContractDescription> contracts
              = importer.ImportAllContracts();
            importer.ImportAllEndpoints();
</pre>
<div class="signature">Marcus Spitzmiller</div>

AnswerRe: calling a web service at runtime Pin
Pete O'Hanlon21-Mar-11 22:57
mvePete O'Hanlon21-Mar-11 22:57 
Questionproblem to connect to Oracle from my C# WinForm program Pin
Gali197821-Mar-11 10:12
Gali197821-Mar-11 10:12 
AnswerRe: problem to connect to Oracle from my C# WinForm program Pin
Wendelius21-Mar-11 10:26
mentorWendelius21-Mar-11 10:26 
AnswerRe: problem to connect to Oracle from my C# WinForm program Pin
Ian Shlasko21-Mar-11 10:30
Ian Shlasko21-Mar-11 10:30 
QuestionWindows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Chesnokov Yuriy21-Mar-11 1:26
professionalChesnokov Yuriy21-Mar-11 1:26 
AnswerRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Pete O'Hanlon21-Mar-11 3:10
mvePete O'Hanlon21-Mar-11 3:10 
QuestionRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Chesnokov Yuriy21-Mar-11 7:18
professionalChesnokov Yuriy21-Mar-11 7:18 
AnswerRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Pete O'Hanlon21-Mar-11 8:23
mvePete O'Hanlon21-Mar-11 8:23 
QuestionRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Chesnokov Yuriy21-Mar-11 10:06
professionalChesnokov Yuriy21-Mar-11 10:06 
AnswerRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Pete O'Hanlon21-Mar-11 10:42
mvePete O'Hanlon21-Mar-11 10:42 
AnswerRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Chesnokov Yuriy22-Mar-11 0:36
professionalChesnokov Yuriy22-Mar-11 0:36 
GeneralRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Pete O'Hanlon22-Mar-11 0:38
mvePete O'Hanlon22-Mar-11 0:38 
GeneralRe: Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change Pin
Chesnokov Yuriy22-Mar-11 21:52
professionalChesnokov Yuriy22-Mar-11 21:52 
QuestionTotal Dynamic Report. Pin
Dot Net Jantu20-Mar-11 20:26
Dot Net Jantu20-Mar-11 20:26 
AnswerRe: Total Dynamic Report. [modified] Pin
SungBae.Han20-Mar-11 22:43
SungBae.Han20-Mar-11 22:43 
GeneralRe: Total Dynamic Report. Pin
Richard MacCutchan20-Mar-11 23:23
mveRichard MacCutchan20-Mar-11 23:23 
GeneralI'm sorry :) Pin
SungBae.Han21-Mar-11 13:02
SungBae.Han21-Mar-11 13:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.