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. Python:文件操作技巧(File operation)(转)

    Python:文件操作技巧(File operation) 读写文件 # ! /usr/bin/python #  -*- coding: utf8 -*- spath = " D:/dow ...

  2. 【OpenStack Cinder】Cinder安装时遇到的一些坑

    最近需要安装Cinder组件,然后遇到了两个比较蛋疼的错误导致controller节点输入cinder service-list一直不能显示cinder节点上的cinder-volume服务. 错误1 ...

  3. 算法-桶排序(Bucket sort)

    本文由@呆代待殆原创,转载请注明出处. 简介:这个排序算法不属于比较排序,在平均情况下他的时间代价是O(n),并且它假设它的输入数据均匀的分布在一个固定的区间里. 思路:桶排序假设他的输入均匀的分布在 ...

  4. TDD开发案例

    前段时间把一个界面框架完成了,今天基于这个框架开发一个小模块,在这里把这个模块设计的全过程记录下来,希望大家讨论并指正. 一.起因 公司交给我一个任务,为测试员写一个手机模拟界面,以方便她们的手机短信 ...

  5. 【主席树】bzoj3653 谈笑风生

    设siz[i]表示i的子树大小-1. 询问中b在a上方的便于统计. 对于b在a下方的情况,贡献为距a距离在K以内的节点的siz之和. 按dfs序建立可持久化线段树,线段树的下标是深度. 相当于把每个点 ...

  6. [USACO2015DEC]Max Flow

    题目大意: 给你一棵n个点的树,有m次操作,每次将给定的路径上所有点的点权+1. 问最后最大的点权是多少. 思路: #include<cstdio> #include<cctype& ...

  7. iOS项目之企业证书打包和发布

    一.打包ipa 个人发布证书和企业发布证书打包 app 大同小异,只是打包时导出选项不同,企业证书打包选择 Save for Enterprise Deployment ,并最终导出 ipa 包.详细 ...

  8. jvm-监视管理控制台-jconsole

    命令: jconsole 作用: jvm进程运行状态的实时.可视化工具 效果: 连接远程jvm进程: 1.首先远程jvm进程,开启了jmx服务: -Dcom.sun.management.jmxrem ...

  9. ajaxfileupload-上传文件示例

    1.引用文件 ajaxfileupload.js @{ ViewBag.Title = "数据导入"; Layout = "~/Views/Shared/_IndexLa ...

  10. 在WPF 4.5中跨线程更新集合

    WPF中一个非常强大的功能是数据绑定,我们可以把一个集合绑定到ListBox中,当集合的数据发生变更时,ListBox界面也会同步变更.本身这是一个非常美好的事情,但是美中不足的是:当把集合绑定到Li ...