I am writing a "universal" client for Web services, and have hit an unexpected problem. I generate the code for the client dynamically by retrieving the Web services WSDL, and using the following (simplified a little) code to generate the client code:
ServiceDescription serviceDescription = ServiceDescription.Read(xmlTextReader(WSDL));
ServiceDescriptionImporter descriptionImporter = new ServiceDescriptionImporter();
descriptionImporter.ProtocolName = "Soap";
descriptionImporter.Style = ServiceDescriptionImportStyle.Client;
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("CSharp");
codeDomProvider.GenerateCodeFromCompileUnit(codeCompileUnit, Console.Out, new CodeGeneratorOptions());
I am testing this using a simple WCF Web service that exposes two methods:
[OperationContract]
int GetInteger();
[OperationContract]
string GetString();
If I examine the client-side generated code, then I can see that the GetString() returns a string, but the GetInteger() method returns void! I assume that this is something to do with value and reference types. Is there some way to force the code generator to make the GetInteger() method return an int?
Copyright Notice:Content Author:「user304582」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11594920/wcf-and-code-generation-from-wsdl