user304582
user304582

Reputation: 2020

WCF and code generation from WSDL

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?

Upvotes: 1

Views: 1051

Answers (2)

user304582
user304582

Reputation: 2020

From various experiments, I believe that my problem is an inherent limitation of using the ServiceDescriptionImporter to generate the client code. I am going to try to "upgrade" to using the System.ServiceModel.Description.WsdlImporter and System.ServiceModel.Description.ServiceContractGenerator framework, in the hopes that improves things.

Upvotes: 0

Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65391

Returning an int over WCF should not be a problem.

Check the code that produces the client side generated code.

The hack to get around the problem would be to return an object that had a single property that was an int.

Upvotes: 2

Related Questions