Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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:
C#
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:
C#
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: http://discoveringdotnet.alexeyev.org/2009/06/wcf-nullable-values-are-not-working-in.html[^]

Ideas appreciated.
Posted
Comments
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>

Hi,

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 : http://msdn.microsoft.com/en-in/library/ms169816.aspx[^]

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

There are some other work around also like modifying your WSDL : http://stackoverflow.com/questions/2426892/wcf-datacontract-does-it-support-nullable-data-member[^]

Or Generate Proxy class at your own and see what error is there : http://msdn.microsoft.com/en-IN/library/ms155134.aspx[^]

Thanks,
Suvabrata
 
Share this answer
 
Comments
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 ( http://stackoverflow.com/questions/2426892/wcf-datacontract-does-it-support-nullable-data-member) 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