如何向wcf服务传递xml类型参数?前台为jquery ajax

nipclyc 2013-05-02 08:53:05
现在前台能收到后台返回的xml数据,但是前台怎样传xml格式的参数到后台,后台又该怎么接收?
我用json传也传不过去,而我用json传输接收数据的时候都是正常的,现在接收数据类型改为xml后,
参数类型不管是json还是xml都不行了传不过去了,麻烦大家给看下,谢谢

以下是契约和实现:

契约
[ServiceContract]
[XmlSerializerFormat]
public interface ILog
{

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
List<LoginResponseBDU> Login(string userid, string password);
}

实现
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Log : ILog
{
public List<LoginResponseBDU> Login(string userid, string password)
{
LoginDAL loginDAL = new LoginDAL();
List<LoginResponseBDU> ResponseList = new List<LoginResponseBDU>();
int status = loginDAL.Login(userid, password, out ResponseList);
return ResponseList;
}
}


以下是配置文件:


<?xml version="1.0" encoding="utf-8"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="wcftest.Log">
<endpoint address="wcftest" kind="webHttpEndpoint" contract="wcftest.ILog" binding="webHttpBinding" bindingConfiguration="webHttpbinding"/>
</service>
</services>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint crossDomainScriptAccessEnabled="True"/>
</webHttpEndpoint>
</standardEndpoints>
<bindings>
<webHttpBinding>
<binding name="webHttpbinding" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点
<serviceMetadata httpGetEnabled="true"/>
要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

</configuration>



以下是前台jquery代码:


$.ajax({
type: "GET",
url: "http://172.168.1.10:1993/Service1.svc/wcftest/Login",
dataType: "xml",
contentType: "json",
data: { "userid": 'mary', "password": '12345' },
success: function (xml) {
$(xml).find('LoginResponseBDU').each(function () {
$strUser = $(this);
User = $strUser.find("autobusiness").text();
})
var detailUrl = "detail.html?id=" + User;
var html = "<tr><td>";
html += User + "</td><td>";
html += "<a href='" + detailUrl + "'>" + User + "</a></td><td>";
html += User + "</td><td>";
html += User + "</td></tr>";
$("#employees").append(html);
// });
$("#employees tr:odd").addClass("oddRow");
}
});
...全文
59 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,263

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧