Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Serialization and parameterized constructor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stan - 19 Jul 2006 18:46 GMT
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
Kevin Yu [MSFT] - 20 Jul 2006 09:52 GMT
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.)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.