庹庹

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1.in wcf sever side,you create this interface

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using NurseWcfLib.NurseWorkServiceReference;
using System.ServiceModel.Web;

namespace NurseWcfLib
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。
[ServiceContract]
public interface INurseWorkSvc
{
[OperationContract]
[WebGet(UriTemplate
= "GetHISAccout/{appid}/{phoneNo}",
ResponseFormat
= WebMessageFormat.Json,
BodyStyle
= WebMessageBodyStyle.Wrapped)]
string GetHISAccout(string appid, string phoneNo);

[OperationContract]
[WebGet(UriTemplate
= "GetNightingale/{appid}/{phoneNo}/{pwd}",
ResponseFormat
= WebMessageFormat.Json,
BodyStyle
= WebMessageBodyStyle.Wrapped)]
Nightingale GetNightingale(
string appid, string phoneNo,string pwd);

[OperationContract]
[WebGet(UriTemplate
= "GetPatientInfo/{department}",
ResponseFormat
= WebMessageFormat.Json,
BodyStyle
= WebMessageBodyStyle.Wrapped)]
IList
<PatientInfo> GetPatientInfo(string department);

[OperationContract]
[WebGet(UriTemplate
= "GetPatientAdvice/{patientNo}/{admissTimes}/{flag}",
ResponseFormat
= WebMessageFormat.Json,
BodyStyle
= WebMessageBodyStyle.Wrapped)]
IList
<PatientAdvice> GetPatientAdvice(string patientNo, string admissTimes, string flag);

[OperationContract]
[WebInvoke(
UriTemplate
= "ConfirmAdvice",
Method
= "POST",
ResponseFormat
= WebMessageFormat.Json,
RequestFormat
= WebMessageFormat.Json,
BodyStyle
= WebMessageBodyStyle.Wrapped)]
int ConfirmAdvice(string his_account, string patientNo, string times);

[OperationContract]
[WebInvoke(
UriTemplate
= "SubmitRecord",
Method
= "POST",
ResponseFormat
= WebMessageFormat.Json,
RequestFormat
= WebMessageFormat.Json,
BodyStyle
= WebMessageBodyStyle.Wrapped)]
int SubmitRecord(NursingRecord record);
}


}

2.the data contract.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace com.guc.android.wcf.datacontract.Nurse
{
[DataContract]
public class NursingRecord
{
//HISAccouns--HIS帐号
//timebh--时间编号
//patientNo--住院号
//admissTimes--住院次数
//position--体温部位
//temperature--体温
//piesis_x--血压x
//piesis_y--血压y
//respiration--呼吸
//pulse --脉搏
//liquidinput--液体入量
//urea--尿液
//bowels--大便次数
//otheroutput--其它排出量

[DataMember]
public string patientNo { set; get; }
[DataMember]
public string admissTimes { set; get; }
[DataMember]
public string timebh { set; get; }
[DataMember]
public string his_account { set; get; }
[DataMember]
public string position { set; get; }
[DataMember]
public string temperature { set; get; }
[DataMember]
public string pulse { set; get; }
[DataMember]
public string respiration { set; get; }
[DataMember]
public string piesis_x { set; get; }
[DataMember]
public string piesis_y { set; get; }

[DataMember]
public string liquidinput { set; get; }
[DataMember]
public string urea { set; get; }
[DataMember]
public string bowels { set; get; }
[DataMember]
public string otheroutput { set; get; }

}
}

 

3.using jquery and send json string parameter to server,the json parameter name must same as the server method parameter.and you can using JSON.stringify(javascriptObject) method to convert an object to jsonstring. for example:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>this is integrated daily report page</title>
<script type="text/javascript" src="../js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="../js/guc_widget.js"></script>
<script type="text/javascript" src="../js/guc_ui.js"></script>
<script>
	$(function() {
		calendarWidget();
		$("#submit").bind("click",function(){
			alert("click submit...");
			submitRecord();
			});
	});

	function submitRecord() {
		$("#jsonstring").html(getRecord());
		$.ajax({
			type : "POST",
			dataType:"json",
			contentType : "application/json",
			url : "http://192.168.0.110:8082/Nurse/SubmitRecord",
			data:getRecord(),
			success : function(result) {
			alert("server result:"+result.SubmitRecordResult);
				hideProgress();
			},
			beforeSend : function() {
				showProgress();
			},
			error : function(xhr) {
				$("#response").html(xhr.responseText)
				hideProgress();
			}
		});
	}
	
	function getRecord(){
		var data={
				record:{
					his_account:"00000",
					timebh:"1",
					patientNo:"*001201",
					admissTimes:"1",
					position:"1",
					piesis_x:"1",
					piesis_y:"1",
					respiration:"1",
					temperature:"36.5",
					pulse:"1",
					liquidinput:"1",
					urea:"1",
					bowels:"1",
					otheroutput:"1"
					}
				}
		return JSON.stringify(data);
		
	}
</script>
</head>
<body>
	<div id="calendarWidget"></div>
	<div id="" style="clear: both"></div>
	<h3>一般护理记录单</h3>
	<div id="jsonstring"></div>
	<div id="response"></div>
	<input type="button" value="submit" id="submit"/>
</body>
</html>

 

posted on 2011-09-13 10:46  庹林  阅读(388)  评论(0编辑  收藏  举报