views:

34

answers:

2

I'm writing a WebService in .NET and use a custom type with no public properties. It looks like this: Class diagramm for MacAddress

It is similar to the built-in type Guid but with special validation rules for MAC addresses. The SOAP description looks like this:

<StringProperty>string</StringProperty>
<GuidProperty>guid</GuidProperty>
<MacAddressProperty />
<!--My aim: <MacAddressProperty>macaddress</MacAddressProperty> -->

My question: Can I create a type like MacAddress to ensure type-safety and use it as parameter for a WebService? How can I say that the delivered string from the caller should be filled in the parameterized constructor (probably like Guid works - it has a constructor with a string-parameter)?

Thanks Alex

+1  A: 

Refer to this post,

http://stackoverflow.com/questions/4019354/do-i-need-to-expose-a-constructor-in-a-wcf-datacontract-for-it-to-work-during-obj/4019582#4019582

A_Nablsi
I'm not sure if it will solve my issue because I don't use WCF. Furthermore the DataContract serialization/deserialisation is only available for >.NET 2.0.
Alex
Whether it is a WCF service or XML Web Service the parameterized constructors can only be used at the service side, at the client side the generated class only have the default constructor, so either you have to create parameterized web methods to return instances of your MacAddress class or use partial class or extension methods to extend the MacAddress class at the client side and implement the validation.I presume the client is not under your control so you have to take the first approach.
A_Nablsi
+1  A: 

If you use properties values in your struct and parametrized it as vieweable by the web service. Your property will be filled/serialized prior sendind it to the client.

See this tutorial, maybe it will help understand the mechanics.

http://www.codeproject.com/KB/WCF/first_WCF_Service.aspx

dutertimes
Maybe I'm wrong but as mentioned in another comment I don't use WCF. Nevertheless I will have a look to the article.
Alex