Serialization and parameterized constructor

S

Stan

Although this issue came up in the web service, I believe it is related to
serialization in general.

This is my web service interface definition:

========

public class HistoryAttribute
{
private int key;
private string value;

public HistoryAttribute()
{
key = -1;
value = string.Empty;
}

public HistoryAttribute(int key, string value)
{
this.key = key;
this.value = value;
}
}

[WebServiceBinding(
Name = "ReportService",
Namespace = "http://PC.WS2",
ConformsTo = WsiProfiles.BasicProfile1_1,
EmitConformanceClaims = true)]
interface IProHistoryService
{
[WebMethod]
void Record(HistoryAttribute[] attributeList);
}

===================

HistoryAttribute class has parameterized constructor:

public HistoryAttribute(int key, string value)
{
this.key = key;
this.value = value;
}


Everything compiles fine, but when a proxy class is generated by WSDL
utility, this constructor is missing:

=======================

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://PC.WS2")]
public partial class HistoryAttribute {

private int keyField;
private string valueField;

}
=============


Only first, default constor is there, and again, no error or warrnings.

I tried to hack it and put parameterized constructo manually, but then I got
an error message during calling the webservice.

I want parameterized constructor because

oProxy.Record (new HistoryAttribute[]
{
new HistoryAttribute (1, "abc"),
new HistoryAttribute (2, "xyz")
})

is shorter than

HistoryAttribute at1 = new HistoryAttribute(1, "abc");
HistoryAttribute at2 = new HistoryAttribute(21, "xyz");

oProxy.Record (new HistoryAttribute[]
{
at1, at2
})


Is there a way around it? Perhaps there is an attribute I need to use?


Thanks,

-Stan
 
K

Kevin Yu [MSFT]

Hi Stan,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to call a parameterized
constructor on your web service. However, it is not generated in the proxy
class. If there is any misunderstanding, please feel free to let me know.

Based on my research, this is a break change in VS2005. You can have a
parameterized constructor on your web service but there will be no way to
call this from your proxy. Instead, it will use the default constructor.

In this case, you can try to use another method to initialize all the
member fields for workaround.

Here is another person who have the same problem as yours.

http://groups.google.com/group/microsoft.public.dotnet.framework.webservices
/browse_thread/thread/7dcbaf997d20e32/c8a3c4b1fa6cd600?lnk=st&q=&rnum=10#c8a
3c4b1fa6cd600

If you have any concerns on this issue, please feel free to let me know.
I'd be happy to work on it with you.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top