A系统传递数据给B系统
1、A创建asmx推送接口如下
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using Topevery.DUM.Report; using Topevery.DUM.Report.Entity; namespace Topevery.DUM.Report.ASMX { /// <summary> /// PreEventFive 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] public class PreEventFive : System.Web.Services.WebService { [WebMethod(Description = "直接返会json")] public string GetPETable() { DateTime now = DateTime.Now; DateTime d1 = new DateTime(now.Year, now.Month, 1); //DateTime d1 = Convert.ToDateTime ("2015-01-01"); DateTime d2 = DateTime.Now; DataTable dt = Broker.GetStatisTypeTop10(d1, d2, 1, "2").Tables[0]; int i = 1; EventDataList DataSource = new EventDataList(); List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); foreach (DataRow dr in dt.Rows) { if (i < 6) { DataSource.SerialNumber.Add(i.ToString()); DataSource.Name.Add(dr["C_NAME"].ToString()); DataSource.LNNUM.Add(dr["C_LA_NUM"].ToString()); } i++; } //数组序列化转为json string jsonData2Tran = Newtonsoft.Json.JsonConvert.SerializeObject(DataSource); //Context.Response.Charset = "GB2312"; //设置字符集类型 //Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //Context.Response.Write(jsonData2Tran); //Context.Response.End(); return jsonData2Tran; } } }
2、B引用A接口,接受该服务数据
JNEvent.PreEventFive ef = new JNEvent.PreEventFive(); string pe = ef.GetPETable(); PreEventFive evt = Newtonsoft.Json.JsonConvert.DeserializeObject<PreEventFive>(pe);
3、发布需要注意的是右击B接口,修改属性-web引用url,将localhost改为外网IP
4、发布后需要在该站点下<system.web>中间配置如下信息,开启远程访问
<webServices> <protocols> <add name="HttpSoap"/> <add name="HttpPost"/> <add name="HttpGet"/> <add name="Documentation"/> </protocols> </webServices>
个人还是觉得.asmx比.ashx方便得多