1、 新建WebApplication1项目

1.1 新建—Web—ASP.NET Empty Web Application--WebApplication1

1.2 添加一个WebForm1

2、 新建webService项目

2.1 新建—Web—ASP.NET Empty Web Application—WebApplicationService

2.2 选择WebApplicationService—右键—Add—WebService (ASMX)-- WebServiceGSS.asmx

2.3 在项目WebApplicationService中添加引用

Microsoft.Practices.EnterpriseLibrary.Data.dll(版本4.1)

Microsoft.Practices.EnterpriseLibrary.Common.dll(版本4.1)

注意,如果报错,Microsoft.Practices.EnterpriseLibrary.Common”類型不能實例化之類的,

可能解決方法:Microsoft.Practices.ObjectBuilder.dll加到References中就哦啦~~~

写服务中的方法,

文件WebServiceGSS.asmx代码:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Services;
  8.  
  9. namespace WebApplicationService
  10. {
  11.  
  12. [WebService(Namespace = "http://Mercer.GlobalSwitchingService/2008/09", Name = "GlobalSwitchingService")]
  13. [System.Web.Services.WebServiceBindingAttribute(ConformsTo = System.Web.Services.WsiProfiles.BasicProfile1_1, EmitConformanceClaims = true, Name = "GlobalSwitchingService")]
  14. [ToolboxItem(false)]
  15. public class WebServiceGSS : System.Web.Services.WebService
  16. {
  17.  
  18. [WebMethod]
  19. public string HelloWorld()
  20. {
  21. return "Hello World";
  22. }
  23.  
  24. [WebMethod(Description = "Returns a list of ReportServerURL one is for source another is for destination")]
  25. public DataSet GetReportServerURL(Guid sourceClientID, Guid destinationClientID)
  26. {
  27. return GSSDML.GetReportServerURL(sourceClientID, destinationClientID);
  28. }
  29.  
  30. [WebMethod(Description = "Returns a list of Roles")]
  31. public DataSet GetReportRole()
  32. {
  33. return GSSDML.GetRole();
  34. }
  35. }
  36. }

文件GSSDML.cs代码(和WebServiceGSS.asmx分开,条理清楚些)

  1. using Microsoft.Practices.EnterpriseLibrary.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.Common;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Web;
  9.  
  10. namespace WebApplicationService
  11. {
  12. public class GSSDML
  13. {
  14. private const string DB_GSS = "DB_GSS";
  15. private const string DB_FAS = "DB_FAS";
  16. public static DataSet GetReportServerURL(Guid sourceClientID, Guid destinationClientID)
  17. {
  18. SqlDataAdapter adapter = new SqlDataAdapter();
  19. DataSet ds = new DataSet();
  20. try
  21. {
  22. using (DbConnection con = DatabaseFactory.CreateDatabase(DB_GSS).CreateConnection())
  23. {
  24. adapter = new SqlDataAdapter();
  25. adapter.SelectCommand = new SqlCommand();
  26. adapter.SelectCommand.Connection = con as SqlConnection;
  27. adapter.SelectCommand.CommandText = "getStudentTable";
  28. adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
  29. //adapter.SelectCommand.Parameters.Add(new SqlParameter("@SourceClientID", sourceClientID));
  30. //adapter.SelectCommand.Parameters.Add(new SqlParameter("@DestinationClientID", destinationClientID));
  31. con.Open();
  32. adapter.Fill(ds);
  33. }
  34. }
  35. catch
  36. {
  37.  
  38. }
  39. return ds;
  40. }
  41.  
  42. public static DataSet GetRole()
  43. {
  44. SqlDataAdapter adapter = new SqlDataAdapter();
  45. DataSet ds = new DataSet();
  46. try
  47. {
  48. using (DbConnection con = DatabaseFactory.CreateDatabase(DB_FAS).CreateConnection())
  49. {
  50. adapter = new SqlDataAdapter();
  51. adapter.SelectCommand = new SqlCommand();
  52. adapter.SelectCommand.Connection = con as SqlConnection;
  53. adapter.SelectCommand.CommandText = " SELECT * from [dbo].[Role]";
  54. adapter.SelectCommand.CommandType = CommandType.Text;
  55. con.Open();
  56. adapter.Fill(ds);
  57. }
  58. }
  59. catch
  60. {
  61.  
  62. }
  63. return ds;
  64. }
  65. }
  66. }

服务中的Config文件

  1. <?xml version="1.0"?>
  2.  
  3. <!--
  4. For more information on how to configure your ASP.NET application, please visit
  5. http://go.microsoft.com/fwlink/?LinkId=169433
  6. -->
  7.  
  8. <configuration>
  9.  
  10. <connectionStrings>
  11. <add name="DB_GSS" connectionString="Database=Test; Server=.; User ID=sa;Password=123;Connection Timeout=90;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient"/>
  12. <add name="DB_FAS" connectionString="Database=fas; Server=.; User ID=sa;Password=123;Connection Timeout=90;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient"/>
  13. </connectionStrings>
  14.  
  15. <system.web>
  16. <compilation debug="true" targetFramework="4.5.2" />
  17. <httpRuntime targetFramework="4.5.2" />
  18. </system.web>
  19.  
  20. </configuration>

3、添加WebService引用

4、添加完成后会出现一个Settings.settings和Web References

5、在WebForm1.aspx.cs中写测试代码

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8.  
  9. namespace WebApplication1
  10. {
  11. public partial class WebForm1 : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. web();
  16. }
  17.  
  18. public void web()
  19. {
  20. ServiceWeb.GlobalSwitchingService serviceWeb = new ServiceWeb.GlobalSwitchingService();
  21. //serviceWeb.Url = "http://localhost:25003/WebServiceGSS.asmx";
  22. //在setting中配置url
  23. //serviceWeb.Url = Properties.Settings.Default.GlobalSwitchingService;
  24. //在config中配置url
  25. //serviceWeb.Url = System.Configuration.ConfigurationManager.AppSettings["GlobalSwitchingService"];
  26. string s = serviceWeb.HelloWorld();
  27.  
  28. Guid id = new Guid();
  29. DataSet ds = serviceWeb.GetReportServerURL(id, id);
  30.  
  31. DataSet ds2 = serviceWeb.GetReportRole();
  32.  
  33. }
  34. }
  35. }

6、如果想自定义服务的端口号,可以在属性的web页设置

在WebService中使用Microsoft.Practices.EnterpriseLibrary.Data配置数据库的更多相关文章

  1. Microsoft.Practices.EnterpriseLibrary.Logging的使用

    翻译 原文地址:http://www.devx.com/dotnet/Article/36184/0/page/1  原文作者:Thiru Thangarathinam (好强大的名字) 翻译: fl ...

  2. c# 之 Microsoft.Practices.EnterpriseLibrary连接Oracle

    首先下载Microsoft Enterprise Library 5.0:http://www.microsoft.com/en-us/download/details.aspx?id=15104,这 ...

  3. Microsoft.Practices.EnterpriseLibrary

    项目中使用了Microsoft.Practices.EnterpriseLibrary这个东西,根据名字猜测和微软有关系(可以翻译为:微软实践企业库). 看到了引入了两个命名空间: using Mic ...

  4. Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, ...

    使用oracle数据库一个多月依赖这问题一直都得不到解决,最近任务不是很忙了,所以决定把这问题解决掉.写一篇文章做记录. 以上错误主要是net程序oracle数据库使用了Microsoft Enter ...

  5. 缓存篇~第六回 Microsoft.Practices.EnterpriseLibrary.Caching实现基于方法签名的数据集缓存

    返回目录 这一讲中主要是说EnterpriseLibrary企业级架构里的caching组件,它主要实现了项目缓存功能,它支持四种持久化方式,内存,文件,数据库和自定义,对于持久化不是今天讨论的重要, ...

  6. VS - Microsoft.Practices.EnterpriseLibrary.Logging

    string fileName = AppDomain.CurrentDomain.BaseDirectory + "\\log.txt";File.AppendAllText(f ...

  7. 错误:创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Caching,

    问题: 错误:创建 cachingConfiguration 的配置节处理程序时出错: 未能加载文件或程序集“Microsoft.Practices.EnterpriseLibrary.Caching ...

  8. Microsoft.Practices.EnterpriseLibrary企业库问题

    System.Configuration.ConfigurationErrorsException: Invalid TraceListenerData type in configuration ' ...

  9. java如何实现webservice中wsdlLocation访问地址的可配置化

    背景:项目中调用了别的系统的webservice接口,调用成功之后发现wsdlLocation的地址是写死的,不方便修改,所以需要实现地址,包括用户名密码的可配置.项目的框架是Spring,调用web ...

随机推荐

  1. 0103 最短Hamilton路径【状压DP】

    0103 最短Hamilton路径 0x00「基本算法」例题 描述 给定一张 n(n≤20) 个点的带权无向图,点从 0~n-1 标号,求起点 0 到终点 n-1 的最短Hamilton路径. Ham ...

  2. Hadoop-eclipse插件配置

    1.准备jar包与安装eclipse. 2.将jar包拷贝到eclipse/plugin.

  3. (转) C#解惑:HashSet<T>类

    HashSet<T>是一个相对“冷门”的类型,平时在项目中用得不多,但是在特定的业务中可以大用. 先来了解下HashSet<T>类,主要被设计用来存储集合,做高性能集运算,例如 ...

  4. 和java面试不得不说的故事

    一直都没有想到,可以有机会可以面试他人,很感谢现在的公司,给我不少的机会可以尝试从不同方面尝试一些工作,在入职现公司之前也作为面试者参加过不少面试,不过还好,面试通过率都还好,大部分是待遇谈不拢.现在 ...

  5. POJ 1113 Wall(凸包)

    [题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...

  6. 【kd-tree】bzoj3489 A simple rmq problem

    Orz zyf教给蒟蒻做法 蒟蒻并不会这题正解……(可持久化树套树?...Orz 对于每个点,我们可以求出pre[i],nex[i],那么询问的答案就是:求max (a[i]),其中 i 满足(pre ...

  7. 【二分答案】【分块答案】【字符串哈希】【set】bzoj2946 [Poi2000]公共串

    我们二分/分块枚举答案x,暴力把除了最短的字符串以外的其他字符串的x长度子串哈希搞出来,分别扔到set里. 然后暴力枚举最短的字符串的x长度字串,查看是否在全部的set里出现过. #include&l ...

  8. 关于SQL优化方面的一些总结

    在sql查询中为了提高查询效率,我们常常会采取一些措施对查询语句进行sql优化,下面总结的一些方法,有需要的可以参考参考. 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 ord ...

  9. [CF911G]Mass Change Queries

    题目大意: 给你一个长度为n的数列a,按顺序进行以下m次操作,每次将区间[l,r]中的所有x变成y,问最后数列是怎样的. 思路: 线段树. 每个线段树结点上维护当前区间每个数分别会变成多少.时间复杂度 ...

  10. React Native使用Navigator组件进行页面导航报this.props....is not a function错误

    在push的时候定义回调函数: this.props.navigator.push({ component: nextVC, title: titleName, passProps: { //回调 g ...