三同时接口(调用外部的webService)
A、添加WebService引用
using JMJS.BusinessLogic.IsSupervisionsServiceReference;
B、具体调用
public class IsSupervisionsInterfaceControl
{
/// <summary>
/// 发送数据到三同时接口
/// </summary>
/// <param name="accept">受理信息</param>
/// <param name="user">当前用户</param>
/// <returns></returns>
public void SentSupervisions(Accept accept,bool super,SysUser user)
{
if (super)
{
if (accept == null) throw new Exception("数据为空,无法生成");
string RegionID = "440700000000";
if (user != null && !string.IsNullOrEmpty(user.UserRegionID))
{
RegionID = user.UserRegionID;
}
using (ExternalInterfaceSoapClient external = new ExternalInterfaceSoapClient())
{
decimal result = external.ThreeMeantimeAndEnterprise(accept.Project.ProjectID, accept.Project.ProjectContentAndScale, (DateTime)accept.ReplyDate, accept.ReplyNumber, accept.Project.ProjectName, accept.Project.ProjectUnitName, accept.Project.ProjectUnitTel, accept.Project.ProjectBuildAddr, accept.Project.ProjectUnitPostCode, accept.Project.ProjectUnitLinkMan, accept.Project.PrincpalName, RegionID);
SUNCOMPASS.Utils.Log.Log.LogInfo("向三同时接口发送数据成功!,发送详细信息如下:" + accept.Project.ProjectID.ToString() + "," + accept.Project.ProjectContentAndScale + "," + accept.ReplyDate.ToString() + "," + accept.ReplyNumber + "," + accept.Project.ProjectName);
}
}
}
}
公告发布接口(使用HttpWebRequest往指定的网站发送数据)
/// <summary>
/// 将相关环评、试运行受理信息,按指定的格式生成html,然后发布到环保网站。
/// </summary>
/// <param name="accept">受理信息</param>
/// <returns></returns>
private bool ShouLiGoShi(Accept accept)
{
StringBuilder sb = new StringBuilder();
sb.Append("<!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\">");
sb.Append("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><style type=\"text/css\">.title_hb_notice{font-size:14px; font-weight:bold; text-align:center;}.tab_notice{border:1px solid #4f4f4f; background:#4f4f4f; line-height:24px; font-size:12px; margin:0 auto;}.tab_notice_td{background:#fff; padding-left:5px;}.tab_notice_th{border-right:1px solid #fff;border-bottom:1px solid #fff; background:#e4e4e4; font-weight:bold; padding-left:5px;}.w_tab_th{80px;}.w_tab_th2{40px;}.name_hb{float:right; margin-right:20px;}</style><title>受理公告</title></head><body><h1 class=\"title_hb_notice\">江门市环境保护局环境影响评价文件审批受理公告</h1><table width=\"96%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"tab_notice\"><tr><td colspan=\"2\" class=\"tab_notice_th w_tab_th\">项目名称</td><td colspan=\"4\" class=\"tab_notice_td\">");
sb.Append(accept.Project.ProjectName);
sb.Append("</td></tr><tr><td width=\"56\" rowspan=\"2\" class=\"tab_notice_th\">建设<br />单位</td><td width=\"64\" class=\"tab_notice_th\">名 称</td><td colspan=\"4\" class=\"tab_notice_td\">");
sb.Append(accept.Project.ProjectUnitName);
sb.Append("</td></tr><tr><td class=\"tab_notice_th\">地 址</td><td colspan=\"2\" class=\"tab_notice_td\">");
sb.Append(accept.Project.ProjectUnitAddr);
sb.Append("</td><td width=\"54\" class=\"tab_notice_td\">邮编</td><td width=\"179\" class=\"tab_notice_td\">");
sb.Append(accept.Project.ProjectUnitPostCode);
sb.Append("</td></tr><tr><td rowspan=\"2\" class=\"tab_notice_th\">环评<br />单位</td><td class=\"tab_notice_th\">名 称</td><td colspan=\"4\" class=\"tab_notice_td\">");
sb.Append(accept.Project.EvaluateUnitName);
sb.Append("</td></tr><tr><td class=\"tab_notice_th\">地 址</td><td colspan=\"2\" class=\"tab_notice_td\">");
sb.Append(accept.Project.EvaluateUnitAddr);
sb.Append("</td><td class=\"tab_notice_td\">邮编</td><td class=\"tab_notice_td\">");
sb.Append(accept.Project.EvaluatePostCode);
sb.Append("</td></tr><tr><td rowspan=\"3\" class=\"tab_notice_th\">环保局</td><td class=\"tab_notice_th\">地 址</td><td colspan=\"2\" class=\"tab_notice_td\">江门市蓬江区农林西路43号之一</td><td class=\"tab_notice_td\">邮编</td><td class=\"tab_notice_td\">529000</td></tr><tr><td class=\"tab_notice_th\">电 话</td><td width=\"152\" class=\"tab_notice_td\">0750-3502020</td><td width=\"78\" class=\"tab_notice_td\">传真</td><td colspan=\"2\" class=\"tab_notice_td\">0750-3502019</td></tr><tr><td class=\"tab_notice_th\">网 页</td><td class=\"tab_notice_td\"> </td><td class=\"tab_notice_td\">E-Mail</td><td colspan=\"2\" class=\"tab_notice_td\"> </td></tr><tr>");
sb.Append("<td colspan=\"2\" class=\"tab_notice_th\">受理日期</td><td colspan=\"4\" class=\"tab_notice_td\">");
sb.Append(string.Format("{0:D}", accept.AcceptDate));
sb.Append("</td></tr><tr><td colspan=\"2\" class=\"tab_notice_th\">公告期限</td><td colspan=\"4\" class=\"tab_notice_td\">");
DateTime dt = (DateTime)accept.AcceptDate;
dt = dt.AddDays(10);
sb.Append(string.Format("{0:D}", accept.AcceptDate) + "——" + string.Format("{0:D}", dt));
sb.Append("</td></tr><tr><td colspan=\"2\" class=\"tab_notice_th\">公告说明</td><td colspan=\"4\" class=\"tab_notice_td\"><p>我局已经受理了本建设项目的环境影响报告书审批申请,为加强社会监督和推进公众参与,根据《环境影响评价公众参与暂行办法》第十三条的规定,特向社会公告受理信息。 <br />社会公民、法人或其他组织需要了解本建设项目及其环评情况的,请与建设单位或环评单位联系索取资料(免费)。 <br />公众可以在公告期限内,以信函、传真或电子邮件等方式,向我局、建设单位或环评单位,提交对本建设项目的书面意见。 </p><p class=\"name_hb\">江门市环境保护局</p></td></tr></table></body></html>");
String sResult = "";
Encoding myEncoding = Encoding.Default;
string param = HttpUtility.UrlEncode("title", myEncoding) + "=" + HttpUtility.UrlEncode(accept.Project.ProjectName, myEncoding)
+ "&" + HttpUtility.UrlEncode("date", myEncoding) + "=" + HttpUtility.UrlEncode(accept.AcceptDate.ToString(), myEncoding)
+ "&" + HttpUtility.UrlEncode("stageType", myEncoding) + "=" + HttpUtility.UrlEncode(accept.Project.StageType, myEncoding)
+ "&" + HttpUtility.UrlEncode("action", myEncoding) + "=" + HttpUtility.UrlEncode(Convert.ToString((int)ActionType.Accept), myEncoding)
+ "&" + HttpUtility.UrlEncode("content", myEncoding) + "=" + HttpUtility.UrlEncode(sb.ToString(), myEncoding);
byte[] postBytes = Encoding.ASCII.GetBytes(param);
try
{
HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(ConfigurationManager.AppSettings["PublicityURL"].ToString());
myWebRequest.Method = "POST";
myWebRequest.ContentType = "application/x-www-form-urlencoded;";
myWebRequest.ContentLength = postBytes.Length;
Stream webStream = myWebRequest.GetRequestStream();
webStream.Write(postBytes, 0, postBytes.Length);
webStream.Close();
HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
StreamReader reader = new StreamReader(myWebResponse.GetResponseStream(),Encoding.UTF8);
sResult = reader.ReadToEnd();
sResult.Trim();
if (sResult == "1")
return true;
else
return false;
}
catch (Exception e)
{
return false;
}
}