Published Thursday, July 31, 2008 7:50 AM by mtaulty

Silverlight 2 Beta 2 - ASMX Services & XmlSerializer

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".


Filed Under: ,

# Silverlight 2 Beta 2 - ASMX Services & XmlSerializer @ Thursday, July 31, 2008 8:06 AM

PingBack from http://work.ezineaerticles.com/silverlight-2-beta-2-asmx-services-xmlserializer/

Silverlight 2 Beta 2 - ASMX Services & XmlSerializer

# Dew Drop - August 1, 2008 | Alvin Ashcraft's Morning Dew @ Friday, August 01, 2008 6:52 AM

PingBack from http://www.alvinashcraft.com/2008/08/01/dew-drop-august-1-2008/

Dew Drop - August 1, 2008 | Alvin Ashcraft's Morning Dew

# Silverlight Cream for August 1, 2008 -- #340 @ Friday, August 01, 2008 5:34 PM

Denislav Savkov with a selection helper class, Mark Monster with SL Tag Cloud, Mike Taulty on asmx web

Community Blogs

# Websites tagged "serialization" on Postsaver @ Tuesday, September 23, 2008 6:02 PM

PingBack from http://www.postsaver.org/tags/serialization

Websites tagged "serialization" on Postsaver