Developing Providers in Visual Basic

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.

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.

System Requirements

To develop providers in Visual Basic 6.0, the following software must be installed on the development computer, in the following order:

  1. Microsoft® Platform SDK (July 2001 or later). Depending on your installation method, choose either the Typical Install option or the following individual components and options:
    • Microsoft Core SDK (Build Environment only)
    • Register Environment Variables
    • Integrate with Microsoft Visual C++
  2. Visual Basic 6.0.
  3. MPF SDK. For more information, see Installing MPF SDK.

Use MPF to test the provider. For more information, see System Requirements and Getting Started.

Creating a Skeleton Project

Use the MPF Provider Wizard to generate a skeleton project.

  1. In Visual Basic 6.0, on the File menu, click New Project.
  2. Click MPF Provider Wizard.
  3. Enter the provider name for the project, then click Next. Extended characters are not supported.
  4. Enter the folder name for the project, then click Next. Extended characters are not supported.
  5. Click Finish. The Project window displays the Modules and Class Modules for the provider.
  6. Open the Class Modules folder and highlight the class file for the provider project.

    The class file implements the MPF IProvProvider interface and procedures for handling each procedure type (Standard, No Rollback, or Two Phase).
Adding a Procedure

To generate a skeleton procedure, use the Add MPF Provider Procedure command.

  1. On the Tools menu, click Add MPF Provider Procedure.
  2. In the Create MPF Provider Procedure window, enter the procedure name. Extended characters are not supported.
  3. Enter a description of the procedure name.
  4. Choose the procedure type: Standard, No Rollback, or Two Phase.
  5. Write the code for each method of the provisioning procedure class.
Building the Provider
Sample Provider

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>
See Also

Developing Custom Namespaces, Developing Custom Providers, sample Visual Basic provider in MPF SDK, Provisioning Schema