views:

12

answers:

1

I have a webservice in C#.NET with the following namespace:

[WebService (Namespace = "http://enterpriseName/wsName")]

The web service contains a WebMethod GetServiceObject and a class MyObject. This web method returns a string whose content is a serialized instance of MyObject.

[WebMethod (MessageName = "GetServiceObjectXML" Description = "Get ServiceObject from Server to Client")]  
public string GetServiceObjectXML ()

This method returns the following XML:

<? Xml version = "1.0" encoding = "utf-16"?>
<ServiceObject Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
<Services>
 <service>
  <id>3</id>
  <date>02/08/2010</date>
 </service>
</Services>
</ServiceObject>

The problem that I encounter is that when I call this method from the client side and try to deserialize this xml to class MyObject and I get a NULL object.

After that I created a new WebMethod with the following signature:

[WebMethod (MessageName = "GetServiceObject" Description = "Get ServiceObject from Server to Client")]
public MyObject GetServiceObject ()

When I call this method from the client side I get the object filled correctly and I can also serialize the object without problems, but the result of serialization is the following xml:

<? Xml version = "1.0" encoding = "utf-16"?>
<ServiceObject Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
<Services Xmlns="http://enterpriseName/wsName"&gt;
 <service>
  <id>3</id>
  <date>02/08/2010</date>
 </service>
</Services>
</ServiceObject>

which is different from the xml generated by the WebMethod GetServiceObjectXML.

How can I get around this, since I intend to use both methods on the same webservice and in the same customer?

A: 

The obvious answer would be, fix GetServiceObjectXML() to return the same XML as GetServiceObject(). The difference seems to be that the object as serialized by the framework has a different XML namespace specified. Whatever method you're using to serialize the object into XML in GetServiceObjectXML() isn't doing that.

Mark