110,534
社区成员
发帖
与我相关
我的任务
分享
契约
[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>
$.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");
}
});
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Runtime.Serialization;
namespace ARTWcf.BusinessEntity.Login
{
[DataContract]
public class LoginRequestBDU
{
private string _userid = "";
private string _password = "";
private Int16 _deviceType;
[DataMember]
public string userid
{
get;
set;
}
[DataMember]
public string password
{
get;
set;
}
[DataMember]
public Int16 deviceType
{
get;
set;
}
public LoginRequestBDU()
{
}
}
}
namespace WcfService1
{
[ServiceContract]
public interface ILog
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
List<LoginResponseBDU> Login(string userid, string password);
}
[DataContract]
public class LoginResponseBDU
{
[DataMember]
public string userid
{
get;
set;
}
[DataMember]
public string password
{
get;
set;
}
[DataMember]
public Int16 deviceType
{
get;
set;
}
}
}
namespace WcfService1
{
[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);
ResponseList.Add(new LoginResponseBDU() {userid=userid,password=password });
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="WcfService1.Log">
<endpoint behaviorConfiguration="Ajaxor" binding="webHttpBinding" contract="WcfService1.ILog"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Ajaxor">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
jq
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">
</script>
</head>
<script type="text/javascript">
$(document).ready(function() {
$('#GetUser').click(function() {
$.ajax({
type: "get",
url: "http://localhost:31162/Service1.svc/Login",
data:"userid=user_sssaaa&password=bbbd",
dataType: "xml",
success: function (employees) {
$(employees).find("LoginResponseBDU").each(function () {
$strUser = $(this);
User = $strUser.find("userid").text();
$("#showname").text("用户名:"+User);
})
},
error:function(a,b,c){alert(c);}
});
});
});
</script>
<body>
<p id="GetUser">GetUser</p>
<p id="showname" style="font-size:20px; background-color:#ffccff"> </p>
</body>
</html>
svc
<%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.Log" CodeBehind="Service1.svc.cs" %>