C# 如何将xml参数发送到WCF?

C# 如何将xml参数发送到WCF?,c#,jquery,ajax,json,wcf,C#,Jquery,Ajax,Json,Wcf,如何将xml参数发送到调用WCF方法?我的客户端代码是使用jQuery在AJAX、JSON中编写的。我想将xml值作为参数传递。如何传递xml值? 我的xml值是 <value><Root>mydata</Root></value> mydata 我的客户端代码-- jQuery.support.cors=true; var bhRequest=“”+ "" + "" + “我的价值”+ "" + "" + ""; $(文档).ready(函

如何将xml参数发送到调用
WCF
方法?我的客户端代码是使用jQuery在
AJAX、JSON
中编写的。我想将xml值作为参数传递。如何传递xml值? 我的xml值是

<value><Root>mydata</Root></value>
mydata
我的客户端代码--


jQuery.support.cors=true;
var bhRequest=“”+
"" +
"" +
“我的价值”+
"" +
"" +
"";
$(文档).ready(函数(){
$(“#btnwcbasichttp”)。单击(函数(){
警报(“hi”);
$.ajax({
类型:“POST”,
url:“http://localhost:8130/MyService.svc/bh/",
数据:请求,
超时:10000,
contentType:“text/xml”,
数据类型:“xml”,
发送前:函数(xhr){
setRequestHeader(“SOAPAction”http://tempuri.org/IMyService/GetSMC");
},
成功:功能(数据){
警惕(“成功”);
$(数据)。查找(“GetSMCResponse”)。每个(函数(){
document.getElementById('Label2')。innerHTML=$(this.find('GetSMCResult').text();
});
},
错误:函数(xhr、状态、错误){
警报(错误);
}
});
});
});

我不确定它是否有效,但请尝试将该XML放入
]>

字符串标记也有一些缺陷,但我不知道是否有必要(也许只有CDATA标记就足够了):

您将使用base64加密并传递它,您可以在服务器客户端上解密

发生了什么?如果没有XML,它还能工作吗?那个参数的类型是什么?我将字符串作为参数传递。它将接受XML字符串,即“OSLWATS”,并返回字符串值。我的意思是它将返回OSLWATS。@Wojciech----谢谢你…..它工作…..)。我使用了它的工作…..:)我还有一个疑问,如何将完整的xml字符串作为参数传递并在结果中获取该xml字符串。我的意思是它将返回mydata
如何以相同的方式传递完整的xml字符串:-)?内置CDATA标签
并在结果中获取xml字符串
我不明白?WCF服务在以字符串形式返回XML时应该没有问题。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js"></script>
        <script type="text/javascript" >

          jQuery.support.cors = true;

            var bhRequest = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                "<s:Body>" +
                "<GetSMC xmlns=\"http://tempuri.org/\">" +
                  "<value><Root>MyValue</Root></value>" +
                "</GetSMC>" +
                "</s:Body>" +
            "</s:Envelope>";

            $(document).ready(function () {
                $("#btnWCFBasicHttp").click(function () {
                    alert("hi");
                    $.ajax({
                        type: "POST",
                        url: "http://localhost:8130/MyService.svc/bh/",
                        data: bhRequest,
                        timeout: 10000,
                        contentType: "text/xml",
                        dataType: "xml",
                        beforeSend: function (xhr) {
                            xhr.setRequestHeader("SOAPAction", "http://tempuri.org/IMyService/GetSMC");

                        },
                        success: function (data) {
                            alert("success");
                            $(data).find("GetSMCResponse").each(function () {

                               document.getElementById('Label2').innerHTML = $(this).find("GetSMCResult").text();
                                                         });
                        },
                        error: function (xhr, status, error) {
                            alert(error);

                        }
                    });
                });
            });
</script>
</head>
<body>
    <form id="form1" runat="server">
      <div>
        <input id="btnWCFREST" type="button" value="Call WCF using JQuery" />
         <label ID="Label1" runat="server" Text="Label"></label>

        </div>
    </form>
   </body>
</html>