WCF and code generation from WSDL
NickName:user304582 Ask DateTime:2012-07-22T02:41:11

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?

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

Answers
Shiraz Bhaiji 2012-07-21T19:57:53

Returning an int over WCF should not be a problem.\n\nCheck the code that produces the client side generated code.\n\nThe hack to get around the problem would be to return an object that had a single property that was an int.",


More about “WCF and code generation from WSDL” related questions

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 (

Show Detail

ServiceRoute + WebServiceHostFactory kills WSDL generation? How to create extensionless WCF service with ?wsdl

I'm trying to use extension-less / .svc-less WCF services. Can anyone else confirm or deny the issue I'm experiencing? I use routing in code, and do this in Application_Start of global.asax.cs:

Show Detail

Remove schema elements from WSDL generated by WCF

I have a Product Datacontract with a couple of Datamembers that are part of a WCF Service. I also serialise and store this Product Datacontract in my app using the DataContractSerializer. Now, I w...

Show Detail

WCF wsdl generation missing WsTrust (RequestSecurityToken)

We have a problem in integrating a wcf service in a web service firewall. Because the wsdl of the service does not contain the operations for ws-trust (requestsecuritytoken, ..). How can I force W...

Show Detail

WCF Custom WSDL XmlSerializerOperationBehavior

I have code that builds a custom WCF wsdl on the fly. In one particular scenario, the WSDL exported should use the XmlSerializerOperationBehavior as the IWsdlExportExtension as opposed to the default

Show Detail

Code generation from WSDL using XML Catalog

Is there any tool for generating Java code from WSDL using XML Catalogs? The problem is that I have wsdl files that import XML schemas which also import other schemas and the schemas are not availa...

Show Detail

Scraping KnownType attributes during SvcUtil and WSDL Code generation

I have a WCF service with a mex endpoint for metadata. I use the SvcUtil through visual studio to generate client data contracts code (C#) while the service is running. SvcUtil adds KnownType attri...

Show Detail

WCF with custom SOAP headers vs. WSDL generation at operation level

I have implemented an operation behavior which reads/writes some out-of-bound information in a custom SOAP message header. By means of implementing IWsdlExportExtension within the behavior class I ...

Show Detail

Wcf binding type from wsdl

Is there a way to retrieve wcf binding type and security mode just from a wsdl? i.e. I want to know what bindings are supported by a wcf service by reading it's wsdl, is it possible? Thanks

Show Detail

WCF From Class Library - hosting in IIS and wsdl generation

Allmost all day today I am trying to research on WCF and one of my aim was to create a WCF service manually (or almost so). Based on few articles on web on how to structure WCF application I have

Show Detail