Monday, January 8, 2007 11:18 PM
by
ggciubuc
Cum "semeni" si cum “mananci” un endpoint.
Dupa cum stiti, pe scurt despre un endpoint se poate spune ca e o poarta de intrare in SQL. Insa ce are asta a face cu titlul acestei interventii ?
Nu numai ca prin el poti sa definesti o cale de intrare in SQL 2005 dar poti sa comunici cu marele ocean SOAP comparabil cu Pacificul!.
Multe din exemplele alaturate discutiei fac apel la aspectul de extragere/vizualizare date din baza de date asa cum apare aici sau prin Books Online. Tot aici (insa fara link) voi prezenta o poarta de intrare in SQL pentru insertie de date. Iata ce voi face:
Mai intai pregatesc procedura stocata suport pentru metoda:
use Test
go
create table Tabel(id int identity, msg xml);
go
CREATE PROC dbo.InsertPackageProc
@pack varchar(max)
AS
begin
declare @xmlpack xml
set @xmlpack=cast(@pack as xml)
insert into Tabel values (@xmlpack)
end
go
Mai departe creez un endpoint care defineste in fapt un serviciu web (GetDataIn) astfel ca sa pot insera xml-uri in acel tabel definit mai sus:
CREATE ENDPOINT InsertData
STATE = STARTED
AS HTTP
(
PATH = '/InsertingData',
AUTHENTICATION = (INTEGRATED),
PORTS = (CLEAR),
SITE = 'diadmin1'
)
FOR SOAP
(
WEBMETHOD 'GetDataIn'
(NAME='DEM.dbo.InsertPackageProc'),
BATCHES = DISABLED,
WSDL = DEFAULT,
DATABASE = 'DEM',
NAMESPACE = 'http://tempUri.org/'
)
GO
Testarea se face in felul urmator :
Intr-o fereastra Internet Explorer se lanseaza http://diadmin1//InsertingData?wsdl (atentie dvs. puneti in loc de “diadmin1” numele serverului dvs in caz ca vreti sa ma verificati); semnul ca totul e ok este un carnat mare de XML ; iata ceva din el:
….
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:sqloptions="http://schemas.microsoft.com/sqlserver/2004/SOAP/Options" xmlns:s0="http://tempUri.org/" xmlns:tns="http://tempUri.org/" targetNamespace="http://tempUri.org/">
…
<xsd:documentation xml:lang="en">XML Schema describing the base types to which SQL Server types are being mapped. For more information, please consult the documentation. (c) Copyright 2004, Microsoft Corporation The following schema for Microsoft SQL Server is presented in XML format and is for informational purposes only. Microsoft Corporation ("Microsoft") may have trademarks, copyrights, or other intellectual property rights covering subject matter in the schema. Microsoft does not make any representation
….
Pana acum am semanat acuma haideti sa mai si mancam ce am pus!
O putem face in 2 feluri (felurile care mi-au trecut mie prin cap):
1. exact ca pe site-ul de mai sus, putem descarca aplicatia XMLSPY de la www.altova.com si punem http://diadmin1//InsertingData?wsdl dupa ce am lansat “Create new SOAP request” din meniul SOAP apoi “Send request to server” din acelasi meniu, sau
2.Creez in Visual Studio 2005 un proiect windows
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Dim ws As sqlhttp.InsertData = New sqlhttp.InsertData
ws.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim sir As String
sir = "<" & Me.txtMesaj.Text & "/>"
ws.GetDataIn(sir)
MsgBox("ok")
End Sub
Si uite asa dupa carnati, sarmale, toba si piftie aveti in meniu si endpointuri
Pofta buna!
Gigi Ciubuc