Click here to Skip to main content
15,174,684 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This appears to be a .NET bug, but curious if anyone else has seen it or knows a way around it. I've got a custom data type something like this:
public class TestContract<T>
    public T Result { get; set; }
    public int? ResultID { get; set; }

I then want to use that type as the result of a web service call, like so:
public TestContract<string> MyWebMethod()
    return new TestContract<string>() { Result = "", ResultID = 123 };

Service project compiles just fine. But try to add a service reference back on the main project, and you'll find that the proxy class is empty. The fix? Remove the question mark from int in ResultID, making it non-nullable. Service references seem to work fine with closed generics, and fine with nullable types, but for some reason can't resolve when they have both.

I've found no solutions to this, and no other acknowledgment of the problem other than here, from 5 years ago:[^]

Ideas appreciated.
ashok rathod 7-Oct-14 22:57pm
can't you use Nullable<int> instead of int? ?
woopsydoozy 9-Oct-14 9:16am
int? is just a shortcut for Nullable<int>


I have used null-able data types as data contract in WCF and its working in live environment for last 2.5 years.

Actual problem at your WSDL your code generator unable to understand class or property details from it.

How to Find wsdl : http://[Your Domain or IP/[Folder]/[Service File Name]?wsdl

When you consume a service at your application (.Net) it will call its wsdl and create the proxy class, now what you are using it will work WCF to .Net application but what about other language.

Now consume it as web reference it will solve your problem.

How to Add Web reference :[^]

Service Reference is .Net to .Net and Web reference .Net to other language.

There are some other work around also like modifying your WSDL :[^]

Or Generate Proxy class at your own and see what error is there :[^]

woopsydoozy 9-Oct-14 9:30am
Thanks, but this does not answer my question. I know how to create a web reference, and I am doing so successfully except in the case where I have nullable property AND a generic type in my contract. The problem is not in the WSDL, as the only difference between a WSDL created when the property is nullable and when the property is not nullable is the attribute nillable="true" on that element. Appears instead to be a bug in MS's proxy generation. Interesting, though--the last response in your next to last link ( shows that someone else encountered the same issue I have. Still looking for a solution.
Suvabrata Roy 9-Oct-14 9:53am
Please post the whole code. I have same kind of DataMembar (with Nullable Field) and its running properly.
woopsydoozy 9-Oct-14 17:34pm
Do you have a generic? Look at my TestContract object--that gives you all you need to reproduce. Copy/paste that to new class (I've got mine in a separate project holding all my data models, not sure if that matters). Create web service. Copy/paste method above into new service. Finally create a client consumer project and try to add a web reference to the web project.
Suvabrata Roy 10-Oct-14 0:14am
Yes dud its generic... Please post your code other wise its very difficult to solve it.

Suvabrata Roy 13-Oct-14 0:44am
why down voted ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900