为具有泛型类型param和nullable属性的类型添加服务引用 [英] Add service reference for type with both generic type param and nullable property

查看:77
本文介绍了为具有泛型类型param和nullable属性的类型添加服务引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个.NET错误,但好奇是否有其他人已经看过它或知道解决方法。我有一个这样的自定义数据类型:

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; }
}





然后我想使用该类型作为Web服务调用的结果,如所以:



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 };
}





服务项目编译得很好。但是尝试在主项目上添加一个服务引用,你会发现代理类是空的。修复?从ResultID中的int中删除问号,使其不可为空。服务引用似乎可以在封闭的泛型中正常工作,并且可以使用可以为空的类型,但由于某种原因,当它们同时存在时无法解决。



我发现没有从5年前开始,除此之外没有其他问题的解决方案: http://discoveringdotnet.alexeyev.org/2009/06/wcf-nullable-values-are-not-working-in.html [ ^ ]



想法赞赏。



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.

推荐答案

根据Microsoft,它已在即将发布的版本中修复:

https://connect.microsoft .COM / VisualStudio中/反馈/信息/ 997590 / WCF-S ervice-reference-with-generic-and-nullable-property-wonr-produce-proxy [ ^ ]
Per Microsoft, it's fixed in an upcoming release:
https://connect.microsoft.com/VisualStudio/feedback/details/997590/wcf-service-reference-with-generic-and-nullable-property-wonr-produce-proxy[^]






我在WCF中使用了无效数据类型作为数据合约,并且在过去的2。5年里在现场环境中工作。



您的WSDL上的实际问题您的代码生成器无法从中了解类或属性详细信息。



如何查找wsdl:http:// [您的域名或IP / [文件夹] / [服务文件名]?wsdl



当您在应用程序(.Net)上使用服务时,它将调用其wsdl和创建代理类,现在你正在使用它将WCF工作到.Net应用程序但是其他语言呢。



现在将它作为Web引用使用它将解决你的问题问题。



如何添加Web引用: http://msdn.microsoft.com/en-in/library/ms169816.aspx [ ^ ]



服务参考是.Net到.Net和Web参考.Net到其他语言。



还有其他一些也可以修改您的WSDL: http://stackoverflow.com/ questions / 2426892 / wcf-datacontract-does-it-support-nullable-data-member [ ^ ]



或者自己生成Proxy类并查看有什么错误: http://msdn.microsoft.com/en-IN/library/ms155134.aspx [ ^ ]



谢谢,

Suvabrata
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


这篇关于为具有泛型类型param和nullable属性的类型添加服务引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆