Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Silverlight 2 Beta 2 - ASMX Services & XmlSerializer
Mike Taulty's Blog

Mike's Badges

Follow on Twitter
View mike's profile on slideshare
Add to Technorati Favorites
CW Blog Awards

It wasn't clear to me from reading the Silverlight SDK docs whether or not you could call ASMX services from Silverlight 2 Beta 2 if calling those services meant involing the XmlSerializer.

Silverlight is using WCF to call services and WCF usually uses the DataContractSerializer. This is a clever serializer but one of the things that it doesn't do ( which I never understood the rationale for ) is serialize XML attributes. It is as element-centric as a serializer can be.

So, I read in the Silverlight SDK docs;

Using XmlSerializer

  • Silverlight 2 Beta 2 supports XmlSerializer. The equivalent serialization support in WCF is described in XML and SOAP Serialization.
  • In Silverlight 2 Beta 2, generating SOAP messages as described in the preceding document is not supported.

and I didn't understand whether those 2 sentences combined to say "Supported" or "Not Supported". Having read it twice, I think what it means is that the XmlSerializer bits are supported but the bits referenced here are not. That's what I think it means but I can't be 100% sure.

And so I built a quick ASMX service as in;

public class Operand
{
  [System.Xml.Serialization.XmlAttribute]
  public int X { get; set; }

  [System.Xml.Serialization.XmlAttribute]
  public int Y { get; set; }
}

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
  public WebService()
  {
  }
  [WebMethod]
  public int Add(Operand op)
  {
    return (op.X + op.Y);
  }
}

and added a reference to it from my Silverlight 2 Beta 2 project and the proxy generation seemed to work ok and, specifically, I could see that the generated proxy code is using the XmlSerializer;

namespace SilverlightApplication3.ProxyCode {
    
    
    [System.ServiceModel.ServiceContractAttribute()]
    public interface WebServiceSoap {
        
        [System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/Add", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute()]
        System.IAsyncResult BeginAdd(SilverlightApplication3.ProxyCode.Operand op, System.AsyncCallback callback, object asyncState);
        
        int EndAdd(System.IAsyncResult result);
    }

and then I called the service using the proxy and it all seemed to work fine. Note that I had to manually add a reference to System.Xml.Serialization.dll in order to get the client to compile but that's fine.

So..."seems to work".


Posted Thu, Jul 31 2008 7:50 AM by mtaulty
Filed under: ,

Comments

Silverlight 2 Beta 2 - ASMX Services & XmlSerializer wrote Silverlight 2 Beta 2 - ASMX Services & XmlSerializer
on Thu, Jul 31 2008 8:06 AM
Dew Drop - August 1, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - August 1, 2008 | Alvin Ashcraft's Morning Dew
on Fri, Aug 1 2008 6:52 AM
Community Blogs wrote Silverlight Cream for August 1, 2008 -- #340
on Fri, Aug 1 2008 5:34 PM
Denislav Savkov with a selection helper class, Mark Monster with SL Tag Cloud, Mike Taulty on asmx web
Websites tagged "serialization" on Postsaver wrote Websites tagged "serialization" on Postsaver
on Tue, Sep 23 2008 6:02 PM
(C) Mike Taulty, 2009. All rights reserved. The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems