sql端点应用
CREATE DATABASE test
USE test
GO
CREATE TABLE [dbo].[tb]
(
[id] [int] IDENTITY(1, 1)
NOT NULL ,
[v] [varchar](50) COLLATE Chinese_PRC_CI_AS
NULL
)
ON [PRIMARY]
GO
CREATE PROC [dbo].[getMyData]
AS
SELECT ID ,
V
FROM tb
GO
CREATE PROC [dbo].[getMyDataByID] ( @id INT )
AS
SELECT ID ,
V
FROM tb
WHERE ID = @ID
GO
CREATE ENDPOINT myTestPoint STATE = STARTED AS HTTP ( PATH = '/sql',
AUTHENTICATION = ( INTEGRATED ), PORTS = ( CLEAR ), SITE =
'FREESKYC-E05267' --机器名,也可以是ip
) FOR SOAP ( WEBMETHOD 'GetMyData' ( NAME= 'test.dbo.getMyData', SCHEMA=
STANDARD ), WEBMETHOD 'GetMyDataByID' ( NAME= 'master.dbo.getMyDataByID' ),
WSDL = DEFAULT, SCHEMA = STANDARD, DATABASE = 'test', NAMESPACE =
'http://tempUri.org/' ) ;
GO
DROP ENDPOINT myTestPoint
--endpoints
SELECT *
FROM sys.endpoints ;
SELECT *
FROM sys.http_endpoints ;
--方法
SELECT *
FROM sys.endpoint_webmethods ;
http://freeskyc-e05267/sql?wsdl.
C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Net;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
cctv.myTestPoint p = new WindowsApplication1.cctv.myTestPoint();
p.UseDefaultCredentials = false;
System.Net.CredentialCache myCreds = new System.Net.CredentialCache();
myCreds.Add(new Uri(p.Url), "NTLM", System.Net.CredentialCache.DefaultCredentials.GetCredential(new Uri(p.Url), "NTLM"));
p.Credentials = myCreds;
DataSet ds = (DataSet)((p.GetMyData())[0]);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Net;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
cctv.myTestPoint p = new WindowsApplication1.cctv.myTestPoint();
p.UseDefaultCredentials = false;
System.Net.CredentialCache myCreds = new System.Net.CredentialCache();
myCreds.Add(new Uri(p.Url), "NTLM", System.Net.CredentialCache.DefaultCredentials.GetCredential(new Uri(p.Url), "NTLM"));
p.Credentials = myCreds;
DataSet ds = (DataSet)((p.GetMyData())[0]);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
}
}