Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF服务接口-XElement与XmlElement与xml字符串_C#_Xml_Wcf_Rest_Soap - Fatal编程技术网

C# WCF服务接口-XElement与XmlElement与xml字符串

C# WCF服务接口-XElement与XmlElement与xml字符串,c#,xml,wcf,rest,soap,C#,Xml,Wcf,Rest,Soap,我正在做一些需要WCF服务接口的工作(在C#中)。交换(发送和接收)的数据将采用xml格式——我不能使用强数据类型,因为接口需要支持具有不同需求的多个客户端 我的问题是,以下哪一项更可取: XElement MyServiceMethod(XElement inputParam 1) { XElement retValue; // // Operation occurs here // return (retValue); } vs // //i

我正在做一些需要WCF服务接口的工作(在C#中)。交换(发送和接收)的数据将采用xml格式——我不能使用强数据类型,因为接口需要支持具有不同需求的多个客户端

我的问题是,以下哪一项更可取:

XElement MyServiceMethod(XElement inputParam 1)
{

    XElement retValue;

    //
    // Operation occurs here
    //

    return (retValue);

}
vs

//
//inputParam is an xml formatted string
//
string MyServiceMethod(string inputParam 1)
{

    string retValue;

    //
    // Operation occurs here
    //

        //retValue is an xml formatted string
    return (retValue);

}
XmlElement MyServiceMethod(XmlElement inputParam 1) {

}

vs

//
//inputParam is an xml formatted string
//
string MyServiceMethod(string inputParam 1)
{

    string retValue;

    //
    // Operation occurs here
    //

        //retValue is an xml formatted string
    return (retValue);

}
代码将主要通过SOAP接口使用,尽管最终也可能通过REST使用


是否有“最佳”方法"? 同样,还有一种是完全不可取的。

我认为REST不会很好地处理XmlElement或XElement。因为
XElement
XElement
都是C类型,如果您想要最大的互操作性和简单类型,只需使用
string
。字符串可以是XML。在服务内部,您可以使用
XDocument.Parse
将字符串XML加载到XDocument中进行解析。根据情况,我同时使用XmlElement(纯XML)和XElement(XML Linq)。如果要执行大量查询,我会使用Linq。我认为REST不会很好地处理XmlElement或XElement。因为
XElement
XElement
都是C类型,如果您想要最大的互操作性和简单的类型,只需使用
string
。字符串可以是XML。在服务内部,您可以使用
XDocument.Parse
将字符串XML加载到XDocument中进行解析。根据情况,我同时使用XmlElement(纯XML)和XElement(XML Linq)。如果要执行大量查询,我将使用Linq。