开发者

ASP.NET WebService how to make a struct be treated as a primitive type for WSDL and serialization

开发者 https://www.devze.com 2023-01-11 04:57 出处:网络
This isssue may have several aspects so please read through first. Suppose that you have a stuct with a few small ints that pack well into Int64 and while you want to use your struct as a type in C#

This isssue may have several aspects so please read through first.

Suppose that you have a stuct with a few small ints that pack well into Int64 and while you want to use your struct as a type in C# you want it to be exposed as In64 via web methods - so that WSDL has it and you retain basic REST ability (simple types make GET invocation possible).

The closest to that I've found so far is SqlDateTime - it auto-mor开发者_运维百科phs into dateTime in WSDL (there's an attrib that seems to govern XSD/WSDL type equivalence plus IXmlSerializable) but that's not enough. The web method still gets recognized as "having complex params" and therefore is rendered unavailable to GET requests.

Update: XSD/WSDL and SOAP invocation respected type equivalency perfectly fine - the problem is with GET invocation - the RESTful URL path doesn't get generated at all.

Looking for info on possible additional attribs, interfaces, hook-up points, of if someone stumbled upon a struct or internal class that managed to do full type equivalence with any "primitive", scalar type (DayTime is not exactly primitive but still gets such treatment). Also if soemone knows a way to establish stronger type equivalence or add/mark a struct to be treated as a simple (scalar) value type - even better.

Please don't post just to say something nasty or preach private ideology. This is serious, gray-zone question for people who know their way in Reflector and read the code. If you think you can ideologize this you don't even have the clue about the issue. If however you can point to actual code that causes/makes the decison about what will be servable via GET request please post even if by doing that you prove the impossibility of extending type equivalence to GET requests.

Oh and CLR is 2.x/3.x.

Thanks to those who help and to those who don't disrupt.


This is not doable.

Why would it be? You're talking about an egregious hack. Why on Earth would .NET ever support it, or allow it?

The only thing you'll be able to do is to implement the IXmlSerializable interface on your struct, so you can do the serialization and deserialization yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消