In Microsoft® Visual Basic®, a custom provider for Microsoft Provisioning Framework (MPF) is implemented as a project with a main class and a separate class for each provisioning procedure. customizes Visual Basic with functions that help you generate the following skeleton files: ProjectNameClass.cls, ProcedureNameClass.cls, ProjectName.xml, and Constants.bas.
In addition, ProjectNameClass.cls contains calls to procedure methods and uses a collection to associate the procedure names with their corresponding classes. Whenever you add a procedure, Visual Basic automatically updates the collection in ProjectNameClass.cls and inserts corresponding method calls.
Procedure Type | Methods | Description |
---|---|---|
Standard | Execute Rollback |
A procedure that reverses updates whenever a transaction is terminated. The corresponding rollback function is called for each action that executed successfully. Rollback functions are called in the reverse order that the execute functions were called. No rollback functions are called if the transaction succeeds. |
No Rollback | Execute | An action that never has to be rolled back, such as a query. |
Two Phase | Execute Rollback Commit Prepare |
An action that implements a two-phase commit plus rollback. This procedure type resembles the Standard procedure type, except that the Prepare and Commit methods are called before the transaction is completed. |
Note For the automatic updates to occur, you must install and use the special MPF SDK functions to set up the project and its procedures. Use the MPF Provider Wizard to generate the project files and, on the Tools menu, use the Add MPF Provider Procedure command to insert the new procedure class and register the procedure in the provider's XML namespace file.
To develop providers in Visual Basic 6.0, the following software must be installed on the development computer, in the following order:
Use MPF to test the provider. For more information, see System Requirements and Getting Started.
Use the MPF Provider Wizard to generate a skeleton project.
To generate a skeleton procedure, use the Add MPF Provider Procedure command.
The following example shows SampleProvider1 with the procedure GetSystemTime. The Add MPF Provider Procedure function generates the following skeleton code for GetSystemTime.cls:
Option Explicit
'Member variable to identify the Provider Type
Public mType As Integer
Public Function Execute(XMLNode As IXMLDOMNode, ProvHelper As IProvHelper)
'The Execute method contains code that should be executed during the provisioning request.
Dim XMLExecData As IXMLDOMNode
Set XMLExecData = XMLNode.selectSingleNode("executeData")
'Clean up constructed objects
Set XMLExecData = Nothing
End Function
Private Sub Class_Initialize()
mType = gcNoRollback
End Sub
GetSystemTime.cls can be implemented in this skeleton code as follows:
Option Explicit
'Member variable to identify the Provider Type
Public mType As Integer
Private Function GetOptionalBoolValue(executeData As IXMLDOMNode, path As String, fDefault As Boolean) As Boolean
Dim elemNode As IXMLDOMNode
Dim attrNode As IXMLDOMNode
Dim attrValue As String
GetOptionalBoolValue = fDefault
Set attrNode = executeData.selectSingleNode(path)
If Not attrNode Is Nothing Then
attrValue = attrNode.Text
If attrValue = "0" Then
GetOptionalBoolValue = False
ElseIf attrValue = "1" Then
GetOptionalBoolValue = True
End If
End If
End Function
Private Sub PutValue(executeData As IXMLDOMNode, Name As String, Value As Variant)
Dim doc As DOMDocument30
Dim elemNode As IXMLDOMElement
Dim textNode As IXMLDOMText
Dim strValue As String
strValue = Value
Set doc = executeData.ownerDocument
Set elemNode = doc.createElement(Name)
Set textNode = doc.createTextNode(strValue)
elemNode.appendChild textNode
executeData.appendChild elemNode
End Sub
Public Sub Execute(XMLNode As IXMLDOMNode, ProvHelper As IProvHelper)
'The Execute method contains code that should be executed during the provisioning request.
Dim XMLExecData As IXMLDOMNode
Set XMLExecData = XMLNode.selectSingleNode("executeData")
'Check for required element.
Dim mode As IXMLDOMNode
Set mode = XMLExecData.selectSingleNode("mode")
If mode Is Nothing Then
Err.Raise 87, "SampleProvider1.SampleProvider1Class", "The required element 'mode' is missing."
End If
'Get the date and time, unless explicitly not wanted.
If GetOptionalBoolValue(mode, "@date", True) Then
PutValue XMLExecData, "date", Date
End If
If GetOptionalBoolValue(mode, "@time", True) Then
PutValue XMLExecData, "time", Time
End If
End Sub
Private Sub Class_Initialize()
mType = gcNoRollback
End Sub
SampleProvider1.xml is the namespace XML generated when you insert the procedure using Add MPF Provider Procedure. As noted earlier, to deploy the provider, you must import this file into the configuration database.
<namespace name="SampleProvider1"
version="1"
providerSource="SampleProvider1.SampleProvider1Class"
description="Namespace for SampleProvider1 containing a sample procedure.">
<procedure name="GetSystemTime"
type="read"
access="public"
description="Sample action gets system time on MPF server"/>
</namespace>
To test the completed procedure, use a sample request with input XML, as in the following code example:
<request>
<procedure>
<execute namespace='SampleProvider1' procedure='GetSystemTime'>
<executeData>
<mode date='1' time='1'/>
</executeData>
<after source='executeData' destination='data' mode='merge'/>
</execute>
</procedure>
</request>
Finally, the request would return an XML response in the following format:
<response>
<data>
<mode date="1" time="1"/>
<date>10/10/2001</date>
<time>1:12:30 PM</time>
</data>
</response>
Developing Custom Namespaces, Developing Custom Providers, sample Visual Basic provider in MPF SDK, Provisioning Schema