programming4us
programming4us
DATABASE

SQL Server 2005 Native XML Web Services : Example Native XML Web Services Project (part 2) - Exposing the Endpoints

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

2. Registering the URL with Http.sys

To register a URL to be handled by SQL Server, execute the following T-SQL:

USE AdventureWorks
GO
EXEC sp_reserve_http_namespace N'http://localhost:80/sql'
GO

3. Exposing the Endpoints

Now that the stored procedures and functions are created and the main URL namespace is registered with Http.sys, the next step is to create the endpoint that exposes the stored procedures as Web services, as shown in Listing 5.

Listing 5. Script to create the AdventureWorks endpoint from CreateEndPoints.sql
USE AdventureWorks
GO
CREATE ENDPOINT AdventureWorks
   STATE = STARTED
AS HTTP(
   PATH = '/sql/AdventureSales',
   AUTHENTICATION = (INTEGRATED),
   PORTS = (CLEAR),
   SITE = 'localhost'
)
FOR SOAP (
   WEBMETHOD 'http://Adventure-Works/'.'GetStoreInfo'
            (NAME='AdventureWorks.dbo.GetStoreInfo',
             SCHEMA=NONE),
   WEBMETHOD 'http://Adventure-Works/'.'GetStoreContacts'
            (NAME='AdventureWorks.dbo.GetStoreContacts',
             SCHEMA=STANDARD),
   WEBMETHOD 'http://Adventure-Works/'.'GetStoreRecentOrders'
            (NAME='AdventureWorks.dbo.GetStoreRecentOrders',
             SCHEMA=STANDARD, FORMAT=ROWSETS_ONLY),
   WEBMETHOD 'GetStoreSalesYTD'
            (name='AdventureWorks.dbo.ufnGetStoreSalesYTD'),
   BATCHES = ENABLED,
   SCHEMA = STANDARD,
   WSDL = DEFAULT,
   DATABASE = 'AdventureWorks',
   NAMESPACE = 'http://Adventure-Works/'
)
GO				  

Let’s take a look at some of the options we chose for the CREATE ENDPOINT statement in Listing 5. We chose to use integrated security over HTTP on port 80 because we will expose this endpoint over the Internet, but only to employees of Adventure Works Cycles who have Windows accounts. We have a WEBMETHOD entry for each of our stored procedures and for the user-defined function. For the ufnGetStoreSalesYTD function, we provided a different name for the Web method than the actual name of the function in the database, for readability. For the stored procedures, we supplied the namespace prefix, but for the function we left it off, taking the default specified in the NAMESPACE attribute. (We did this simply to demonstrate the ability to define a default namespace prefix at the endpoint level and to override it at the Web method level. In this case, the result is the same because the default namespace prefix is the same as the one used for the first three WEBMETHOD entries.)

To allow our client to make ad hoc SQL queries against the database (to support the searching functionality), we set the BATCHES option to ENABLED. Because we know that the client is a Windows Forms application using the .NET Framework 2.0, we used the default WSDL option.

Granting Security Access to the Endpoints

To make it easy to control access to our endpoint and add new users later as needed, we’ll create a Windows Security Group with the name AdventureWorksSalesTeam, as shown in Figure 1. In this figure, we have added the JSmith user to this group. When you create this group on your server, you should add the user you will use to run this application.

Figure 1. Setting up the AdventureWorksSalesTeam security group

Note

In our example, we use a local security group because this is probably how you will want to set up your development environment to run the example. However, in a real environment this should probably be a domain group.


Even though we will grant access to the endpoint to members of the AdventureWorksSales-Team group, we must also grant access to the stored procedures and functions themselves, just as we would for any application. Listing 6 shows the T-SQL statements necessary to grant the AdventureWorksSalesTeam security group access to our stored procedures, function, and endpoint.

Listing 6. Script to grant rights to stored procedures, UDF, and the endpoint from GrantSecurity.sql
USE master
GO
EXEC sp_grantlogin @loginame='DataServer\AdventureWorksSalesTeam'
EXEC sp_grantdbaccess @loginame='DataServer\AdventureWorksSalesTeam'
GO
USE [AdventureWorks]
GO
GRANT EXECUTE ON [dbo].[GetStoreContacts] TO [DataServer\AdventureWorksSalesTeam]
GRANT EXECUTE ON [dbo].[GetStoreInfo] TO [DataServer\AdventureWorksSalesTeam]
GRANT EXECUTE ON [dbo].[GetStoreRecentOrders] TO [DataServer\AdventureWorksSalesTeam]
GRANT EXECUTE ON [dbo].[ufnGetStoreSalesYTD] TO [DataServer\AdventureWorksSalesTeam]
GO
USE master
GO
GRANT CONNECT ON ENDPOINT::AdventureWorks TO [DataServer\AdventureWorksSalesTeam]
GO

					  

Note

In this script, we use the fictional server name DataServer. You should replace all references to DataServer with the name of your server when you set up the sample application to run in your environment.


That’s all there is to it. With just a few extra T-SQL commands, we’ve exposed all of the functionality we need for the Adventure Sales application as a Web service! Let’s go ahead and test the endpoint to make sure everything is working before we start building the client application. We can’t easily test the Web methods without a client application, but we can point to the URL and see that it generates WSDL as it should. See Figure 2 for the result we get when we browse to http://localhost/sql/AdventureSales?wsdl.

Figure 2. The WSDL generated by our endpoint
Other  
  •  SQL Server 2005 Native XML Web Services : Exposing SQL Programmability as Web Services (part 2) - Calling Native XML Web Service Endpoints from Client Applications
  •  SQL Server 2005 Native XML Web Services : Exposing SQL Programmability as Web Services (part 1)
  •  Western Digital Black 4TB Hard Drive - 4TB Storage Goes Mainstream
  •  Intel Solid State Drive 335 Series - Better Under The Hood
  •  HDD, SSD and Hybrid Hard Drive Competition
  •  SQL Server 2008 : Index analysis (part 3) - Identifying index fragmentation
  •  SQL Server 2008 : Index analysis (part 2) - Identifying indexes to add
  •  SQL Server 2008 : Index analysis (part 1) - Identifying indexes to drop/disable
  •  ADO.NET Programming : Microsoft SQL Server CE (part 5) - Querying Schema Information
  •  ADO.NET Programming : Microsoft SQL Server CE (part 4) - Updating a SQL Server CE Database, The SqlCeDataAdapter Class
  •  
    Top 10
    Free Mobile And Desktop Apps For Accessing Restricted Websites
    MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
    TOYOTA CAMRY 2; 2.5 : Camry now more comely
    KIA SORENTO 2.2CRDi : Fuel-sipping slugger
    How To Setup, Password Protect & Encrypt Wireless Internet Connection
    Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
    Backup & Restore Game Progress From Any Game With SaveGameProgress
    Generate A Facebook Timeline Cover Using A Free App
    New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
    SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
    - Messages forwarded by Outlook rule go nowhere
    - Create and Deploy Windows 7 Image
    - How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
    - Creating and using an unencrypted cookie in ASP.NET
    - Directories
    - Poor Performance on Sharepoint 2010 Server
    - SBS 2008 ~ The e-mail alias already exists...
    - Public to Private IP - DNS Changes
    - Send Email from Winform application
    - How to create a .mdb file from ms sql server database.......
    programming4us programming4us
    programming4us
     
     
    programming4us