views:

61

answers:

1

i return an xmlElement from a WCf method. when i do a service reference in the client, the same method is returning XElement instead of XmlElement. i tried everything: updating the service reference, making a new service reference, but it doesn't help.

This is my client:

ServiceReference1.BasicServiceClient basicWCfClient = new ServiceReference1.BasicServiceClient();
        XmlElement xmlelement =  basicWCfClient.GetData(5); 
        basicWCfClient.Close();

i get an error : "Cannot implicitly convert type 'System.Xml.Linq.XElement' to 'System.Xml.XmlElement'"

when the method in the server side:

 public XmlElement GetData(int value)
    {
        XmlDocument xmldoc = new XmlDocument();
        xmldoc.LoadXml("<msg><node1>Hello</node1><node2>World</node2><request_params><mynode>More</mynode></request_params></msg>");
        XmlElement xmlElement = xmldoc.DocumentElement;
        return xmlElement;
     }

and the interface:

    [ServiceContract]
public interface IBasicService
{

    [OperationContract]       
    [WebGet(UriTemplate = "GetData?value={value}")] // Add support for HTTP GET Requests
    XmlElement GetData(int value);}

what is going on ?

A: 

Nothing is wrong. Client doesn't know which .NET type has been used and service reference informs it only that any XML can be returned. It takes XML and provides it as XElement. It is build in behavior and I think it was chosen by MS because of newer and more comfortable API. Why do you need the method to return XmlElement?

Ladislav Mrnka
my test client is indeed compiled in Framework 3.5 but the other company (the true client) wont have Framework 3.5, it works with framework 2.0 and it won't recognise XElement because XElement is Framework 3.5. but on second thought, will my WCF service return XmlElement when the true client (with framework 2.0 environment) will create a service reference? it won't return Xelement right ?
Rodniko
just tried the same reference from VS2005 in framework 2.0 and it indeed returns Xmlelement. The framework environment was the problem, thanks!
Rodniko
First of all when you consume the service in .NET 2.0 you will not be able to use Add service reference because .NET 2.0 doesn't support WCF. You will have to use Add web reference and it will use only .NET 2.0 types.
Ladislav Mrnka
He may be using primarily 2.0 with some of the 3.0 libraries (there was a 3.0 release), which is basically WCF. I've seen that before, so when he says 2.0, he means 3.0, which is 2.0 + WCF (and maybe some other stuff, but I'm not sure on what else was there).
Kevin