解决方案 »
- FlowLayoutPanel 能控制动态生成控件之间的间距吗
- gridview 控件 自带的删除按钮 的求助
- VS2010 2.5G太大了。。如果只是简单地想练编程 有精简版本吗
- 怎样在dataGridView的列头添加combobox
- DataGridView合计行,最后一行可能出现被遮住的情况 如何解决!谢谢
- 错误提示!
- 读取数据量太大,程序运行慢
- 如何安装.net环境?
- 怎样使用C#读取由空格分开的单词序列中的每个单词?
- 请教大家c#接收串口数据怎么进行分析?
- 一函数中怎样调用listbox__DrawItem(object sender, DrawItemEventArgs e)这个事件
- 是不是一个线程对应一个应用程序域?
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" %>
<binding crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
就是错在直接使用 JSON 对象传递给服务方法:
正确做法是:
var newp = {};
newp.id = 299;
newp.first_name = "Sha";
newp.last_name = "Zhang";
newp.country = "USA"; $.ajax({
data: JSON.stringify(newp),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (req, tStatus) {
alert(req);
},
type: "POST",
url: "http://xxxxxxx/xxxxx"
});