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代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services; namespace WebApplicationService
{ [WebService(Namespace = "http://Mercer.GlobalSwitchingService/2008/09", Name = "GlobalSwitchingService")]
[System.Web.Services.WebServiceBindingAttribute(ConformsTo = System.Web.Services.WsiProfiles.BasicProfile1_1, EmitConformanceClaims = true, Name = "GlobalSwitchingService")]
[ToolboxItem(false)]
public class WebServiceGSS : System.Web.Services.WebService
{ [WebMethod]
public string HelloWorld()
{
return "Hello World";
} [WebMethod(Description = "Returns a list of ReportServerURL one is for source another is for destination")]
public DataSet GetReportServerURL(Guid sourceClientID, Guid destinationClientID)
{
return GSSDML.GetReportServerURL(sourceClientID, destinationClientID);
} [WebMethod(Description = "Returns a list of Roles")]
public DataSet GetReportRole()
{
return GSSDML.GetRole();
}
}
}

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

using Microsoft.Practices.EnterpriseLibrary.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Web; namespace WebApplicationService
{
public class GSSDML
{
private const string DB_GSS = "DB_GSS";
private const string DB_FAS = "DB_FAS";
public static DataSet GetReportServerURL(Guid sourceClientID, Guid destinationClientID)
{
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
try
{
using (DbConnection con = DatabaseFactory.CreateDatabase(DB_GSS).CreateConnection())
{
adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand();
adapter.SelectCommand.Connection = con as SqlConnection;
adapter.SelectCommand.CommandText = "getStudentTable";
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
//adapter.SelectCommand.Parameters.Add(new SqlParameter("@SourceClientID", sourceClientID));
//adapter.SelectCommand.Parameters.Add(new SqlParameter("@DestinationClientID", destinationClientID));
con.Open();
adapter.Fill(ds);
}
}
catch
{ }
return ds;
} public static DataSet GetRole()
{
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
try
{
using (DbConnection con = DatabaseFactory.CreateDatabase(DB_FAS).CreateConnection())
{
adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand();
adapter.SelectCommand.Connection = con as SqlConnection;
adapter.SelectCommand.CommandText = " SELECT * from [dbo].[Role]";
adapter.SelectCommand.CommandType = CommandType.Text;
con.Open();
adapter.Fill(ds);
}
}
catch
{ }
return ds;
}
}
}

服务中的Config文件

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
--> <configuration> <connectionStrings>
<add name="DB_GSS" connectionString="Database=Test; Server=.; User ID=sa;Password=123;Connection Timeout=90;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient"/>
<add name="DB_FAS" connectionString="Database=fas; Server=.; User ID=sa;Password=123;Connection Timeout=90;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient"/>
</connectionStrings> <system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web> </configuration>

3、添加WebService引用

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

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

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
web();
} public void web()
{
ServiceWeb.GlobalSwitchingService serviceWeb = new ServiceWeb.GlobalSwitchingService();
//serviceWeb.Url = "http://localhost:25003/WebServiceGSS.asmx";
//在setting中配置url
//serviceWeb.Url = Properties.Settings.Default.GlobalSwitchingService;
//在config中配置url
//serviceWeb.Url = System.Configuration.ConfigurationManager.AppSettings["GlobalSwitchingService"];
string s = serviceWeb.HelloWorld(); Guid id = new Guid();
DataSet ds = serviceWeb.GetReportServerURL(id, id); DataSet ds2 = serviceWeb.GetReportRole(); }
}
}

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. DP(悬线法)+二维前缀和【p2706】巧克力

    Background 王7的生日到了,他的弟弟准备送他巧克力. Description 有一个被分成n*m格的巧克力盒,在(i,j)的位置上有a[i,j]块巧克力.就在送出它的前一天晚上,有老鼠夜袭巧 ...

  2. 树链剖分【p4116】Qtree3 - Query on a tree

    Description 给出N个点的一棵树(N-1条边),节点有白有黑,初始全为白 有两种操作: 0 i : 改变某点的颜色(原来是黑的变白,原来是白的变黑) 1 v : 询问1到v的路径上的第一个黑 ...

  3. React Native之iOS App打包

    iOS打包步骤(一.二.三可不按照顺序) 步骤一: 选择iOS Device(以下两者选其中一个即可) 选择 Generic iOS Device (个人建议使用这个) 选择Generic iOS D ...

  4. &#x开头的是什么编码?

    在 Node 层利用 cheerio 解析网页时,输出的中文内容都是以 &#x 开头的一堆像乱码一样的东西,尝试过各种编码都无效,而且神奇的是,将这一堆“乱码”保存成网页后,通过浏览器打开又可 ...

  5. 使用GIT时排除NuGet的packages文件夹

    这段时间一直在用GIT做本地自己写的程序的源码管理工具,在使用的过程中发现了一个问题:Git往往会把NuGet的packages文件夹作为项目的一部分给添加进来了.网上搜了一下,原因是GIT只是和文件 ...

  6. Easyui的numberbox无法输入以0开头的数字编号(转载)

    1.问题 项目中碰到这样一个问题,Easyui的numberbox在输入数字编号的时候不能以0开头 在我输入以0开头的数字编号后,离开输入框的时候,那个前缀0就自动去掉了. 接下来,我们查看API说明 ...

  7. C#之Raw Socket网络封包监视源码

    大家可以建立一个Windows Form应用程序,在下面的各个文件中添加对应的源码: //RawSocket.csnamespace ReceiveAll{ using System; using S ...

  8. javascript快速入门13--BOM——浏览器对象模型(Browser Object Model)

    什么是BOM? BOM是Browser Object Model的缩写,简称浏览器对象模型 BOM提供了独立于内容而与浏览器窗口进行交互的对象 由于BOM主要用于管理窗口与窗口之间的通讯,因此其核心对 ...

  9. 贯通Spark Streaming流计算框架的运行源码

    本章节内容: 一.在线动态计算分类最热门商品案例回顾 二.基于案例贯通Spark Streaming的运行源码 先看代码(源码场景:用户.用户的商品.商品的点击量排名,按商品.其点击量排名前三): p ...

  10. Netty源码细节IO线程(EventLoop)(转)

    原文:http://budairenqin.iteye.com/blog/2215896 源码来自Netty5.x版本, 本系列文章不打算从架构的角度去讨论netty, 只想从源码细节展开, 又不想通 ...