WSDL接口数据传递以及外网发布需要注意的地方
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;
}
}
}View Code2、B引用A接口,接受该服务数据


JNEvent.PreEventFive ef = new JNEvent.PreEventFive();
string pe = ef.GetPETable();
PreEventFive evt = Newtonsoft.Json.JsonConvert.DeserializeObject<PreEventFive>(pe);View Code3、发布需要注意的是右击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方便得多
相关推荐
xieyixiao 2020-04-16
GUAOSHITAIDU 2011-09-17
人亦有言进退维谷 2013-11-29
kobeyan 2013-06-17
SunnyZero 2013-03-19
draco 2012-05-30
香帅 2011-10-28
oMMing 2011-05-05
84457417 2010-12-16
fengzhizi0 2010-07-15
yhahaha 2010-06-09
AHRL 2008-10-08
XiaoMuFireAnt 2008-03-23
kyle00 2007-12-05
随矜而去BLOG 2011-09-20
程序员吗 2019-03-28
weixuejunphp 2019-04-10