...
To set up an enumerated property, you need to define a type that only allows the values you want. You can do this by creating an enumeration. Start by moving to the end of the template and choosing Edit > Insert Content > Script Block. Then create the new start typing <script which will show you an IntelliPrompt and allow you to autocomplete the script block.
Info |
---|
If you press the tab button or click on the script IntelliPrompt (or any IntelliPrompt) which is shown in the above image, the action will be autocompleted. In this case the script block will be created with an ending script tag. |
After the script block has been created, lets create the new enumeration type:
Code Block | ||
---|---|---|
| ||
<script runat="template"> Public Enum StateEnum STARTED STOPPED DISABLED End Enum </script> |
Now you can use a CodeSmith Generator Property directive to define a property that makes use of the new type:
...
Code Block | ||
---|---|---|
| ||
<%@ CodeTemplate Language="VB" TargetLanguage="T-SQL" Description="Create an HTTP Endpoint." %> <%@ Property Name="InitialState" Type="StateEnum" Category="Options" Default="STARTED" Description="The initial state of the Web service." %> <%@ Property Name="Authentication" Type="AuthenticationEnum" Category="Options" Default="INTEGRATED" Description="Authentication method." %> <%@ Property Name="Port" Type="PortsEnum" Category="Options" Default="CLEAR" Description="Port to use." %> |
Code Block | ||
---|---|---|
| ||
CREATE PROC dbo.PersonAddressTypeProc
AS
SELECT
AddressTypeID,
Name,
rowguid,
ModifiedDate
FROM
Person.AddressType
GO
CREATE ENDPOINT GetAddressType
STATE = <%= GetState(InitialState) %>
AS HTTP
(
PATH = '/AddressType',
AUTHENTICATION = (<%= GetAuthentication(Authentication) %>),
PORTS = (<%= GetPort(Port) %>),
SITE = 'localhost'
)
FOR SOAP
(
WEBMETHOD 'AddressTypeList'
(NAME='AdventureWorks.dbo.PersonAddressTypeProc'),
BATCHES = DISABLED,
WSDL = DEFAULT,
DATABASE = 'AdventureWorks',
NAMESPACE = 'http://AdventureWorks/AddressType'
)
GO
|
Code Block | ||
---|---|---|
| ||
<script runat="template">
Public Enum StateEnum
STARTED
STOPPED
DISABLED
End Enum
Public Enum AuthenticationEnum
BASIC
DIGEST
NTLM
KERBEROS
INTEGRATED
End Enum
Public Enum PortsEnum
CLEAR
SSL
End Enum
Public Function GetState (ByVal State As StateEnum) As String
Select Case State
Case StateEnum.STARTED
GetState = "STARTED"
Case StateEnum.STOPPED
GetState = "STOPPED"
Case StateEnum.DISABLED
GetState = "DISABLED"
End Select
End Function
Public Function GetAuthentication (ByVal Authentication As AuthenticationEnum) As String
Select Case Authentication
Case AuthenticationEnum.BASIC
GetAuthentication = "BASIC"
Case AuthenticationEnum.DIGEST
GetAuthentication = "DIGEST"
Case AuthenticationEnum.NTLM
GetAuthentication = "NTLM"
Case AuthenticationEnum.KERBEROS
GetAuthentication = "KERBEROS"
Case AuthenticationEnum.INTEGRATED
GetAuthentication = "INTEGRATED"
End Select
End Function
Public Function GetPort (ByVal Port as PortsEnum) As String
Select Case Port
Case PortsEnum.CLEAR
GetPort = "CLEAR"
Case PortsEnum.SSL
GetPort = "SSL"
End Select
End Function
</script> |
So far, so good. But there's still one thing missing: a connection to the database. We'll tackle that next.
Info |
---|
Don't forget to save your template by clicking on the Save icon or selecting File -> Save from the menu located at the top of the Generator Template Editor. |
Next: Setting up a SQL Property
...
More information:
...