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. MPF SDK customizes Visual Basic with functions that help you generate the following skeleton files: ProjectNameClass.cls, ProcedureNameClass.cls, ProjectName.xml, and Constants.bas.
- The ProjectNameClass.cls file implements the IProvProvider interface. IProvProvider activates and deactivates the provider, manages requests, and initiates rollback.
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.
- Each ProcedureName.cls file contains methods for each phase of a provisioning transaction. These methods vary depending on the procedure type.
Procedure Type Methods Description Standard Execute
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
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.
- As you create the provider, Visual Basic updates the ProjectName.xml file, the namespace file that registers the provider and its procedures in the configuration database. When you are ready to deploy the provider, you must add this file to the database using the steps described in Registering Namespaces in MPF.
- The Constants.bas file contains any constants shared between the class files.
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:
- 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++
- Visual Basic 6.0.
- 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.
- In Visual Basic 6.0, on the File menu, click New Project.
- Click MPF Provider Wizard.
- Enter the provider name for the project, then click Next. Extended characters are not supported.
- Enter the folder name for the project, then click Next. Extended characters are not supported.
- Click Finish. The Project window displays the Modules and Class Modules for the provider.
- 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.
- On the Tools menu, click Add MPF Provider Procedure.
- In the Create MPF Provider Procedure window, enter the procedure name. Extended characters are not supported.
- Enter a description of the procedure name.
- Choose the procedure type: Standard, No Rollback, or Two Phase.
- Write the code for each method of the provisioning procedure class.
Building the Provider
- On the File menu, click Make <ProjectName>.dll.
- Use regsvr32.exe to register the provider in Microsoft. Windows..
- Register the namespace from either Provisioning Manager or the command line.
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
Top of Page
© 1999-2002 Microsoft Corporation. All rights reserved.