加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

SqlSever 2000 访问 .net WebService

发布时间:2020-12-17 00:20:35 所属栏目:安全 来源:网络整理
导读:测试环境: 服务器系统:Win 2003 数据库:Ms SqlServer 2000 工具: Soap Toolkit3.0 开发工具:vs 2010 新建一个WebService 工程 只列式asmx文件代码 namespace WebApplication1{ /// summary /// WebService1 的摘要说明 /// /summary [WebService(Namespace

测试环境:

服务器系统:Win 2003

数据库:Ms SqlServer 2000

工具: Soap Toolkit3.0

开发工具:vs 2010

新建一个WebService 工程

只列式asmx文件代码

namespace WebApplication1
{
    /// <summary>
    /// WebService1 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/",Name="TS")]//注意这里的“TS”,他才是webservice的名字,而不是WebService1
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
     [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {


        [WebMethod(BufferResponse = false)]
        public string InitData()
        {
            return "这是一个测试";
        }
    }
}

将webservice发布,地址:http://IP地址/vbweb1/

编写sqlserver测试存储过程,代码如下

exec sp_configure 'show advanced options',1 ;
reconfigure
sp_configure 'Ole Automation Procedures',1;/*执行该语句时,报错:“配置选项 'Ole Automation Procedures' 不存在,也可能是高级选项。”,但是对于本次测试并没有什么影响。*/reconfigure
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

Create   procedure sp_WebServiceTest
as
declare @Hr int,@Object int
declare @RtnMsg nvarchar(100)
set @Hr = 0
set @Object = 0
set @RtnMsg = ''

exec @Hr=sp_OACreate 'MSSOAP.SoapClient30',@Object out /*这里是MSSOAP.SoapClient30,因为我的系统win2003,如果用MSSOAP.SoapClient,执行存储过程会报错;如果winxp系统,两个都可以用*/

exec @Hr=sp_OAMethod @Object,'MSSoapinit',NULL,'http://IP地址/vbweb1/WebService1.asmx?wsdl','TS' /*看到了吗?这里是TS。*/

exec @Hr=Sp_OAMethod @Object,'InitData',@RtnMsg out


if @Hr <> 0
begin
 print '1'
 Exec Sp_OAGetErrorInfo @Object
 select @Object
end
else
begin
    print '2'
 Select @RtnMsg
end

exec @Hr=sp_OADestroy @Object

 

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


?


执行存储过程。

sp_WebServiceTest
等到的结果

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读