Partager via


Creating an Instance of an Address Resource

Adding a new address resource does not require that you define a new resource schema as described in Defining the Schema for a Custom Resource. The schema of an address resource is already defined by the resource class MSCS_Address, as found in the s_ClassName column of the SystemProps table in the Administration database (MSCS_Admin). Corresponding to this resource class (in the same table row) is the value Address in the s_ResourceType column, which in turn identifies several extended properties in the ExtendedProps table. In addition to the basic resource properties associated with the columns in the SystemProps table, all address resources have a standard set of extended properties. These properties are associated with rows in the ExtendedProps table for which the s_ResourceType column is set to the value Address.

Each address resource represents an application, such as a Web site or a Web service that functions as a part of the larger Commerce Server 2009 site. Each such application can be deployed to multiple Web servers to adequately service your expected load. In Commerce Server Manager, the Web servers to which an application is deployed are displayed as Web server nodes within each application node. Both the application nodes and the Web server nodes have property dialog boxes associated with them through which the various address resource extended properties can be viewed and modified. The following table shows the extended properties for address resources, together with their data type and default value, if any. The extended properties that have a data type of "array of strings" are the properties that are associated with Web servers. Generally, the length of the arrays will correspond to the number of Web servers deployed for that address resource.

Address resource extended property

Data type

Default value

b_CookiePath_ApplicationScope

Boolean

True

b_Site_Track_AutoAnonymous

Boolean

False

b_SyncLogFile

Boolean

True

f_EnableHTTPS

Integer

<none>

s_CurrentServer

Integer

<none>

s_NumberOfServers

Integer

<none>

u_auth_mode

Integer

<none>

u_CookieDomain_Scope

Integer

<none>

s_NonSecureHostname

String

<none>

s_SecureHostname

String

<none>

s_VirtualRootName

String

<none>

s_DirectoryIndexFiles

Array of strings

<none>

s_IPAddress

Array of strings

<none>

s_IPPort

Array of strings

<none>

s_LocalDomain

Array of strings

<none>

s_LogFileCodePage

Array of strings

<none>

s_LogFileDirectory

Array of strings

<none>

s_LogFilePeriod

Array of strings

<none>

s_LogType

Array of strings

<none>

s_SecureBindings

Array of strings

<none>

s_SecureIPPort

Array of strings

<none>

s_ServerBindings

Array of strings

<none>

s_URLEncodingCodePage

Array of strings

<none>

s_UseHostName

Array of strings

<none>

s_WebServerFullName

Array of strings

<none>

s_WebServerInstance

Array of strings

<none>

s_WebServerMachine

Array of strings

<none>

s_WebServerName

Array of strings

<none>

The following code shows how to create an address resource programmatically using the CreateComponentConfig method of the SiteConfigFreeThreaded object, in addition to how to programmatically set various properties, both basic and extended, of the address resource. Pay extra attention to the following sections of the code sample, as they apply specifically to creating and initializing address resources (also highlighted in bold font).

  • When you call the CreateComponentConfig method, pass the string "MSCS_Address" as the value of the "bstrConfigSchemaClass" parameter in order to create a Commerce Server 2009 address resource.

  • You can set the basic property s_ProgIDPUP to the out-of-the-box PUP object by using the ProgID "Commerce.AddressPuP" in order to use its built-in functionality to package and unpackage your address resource.

  • If your address resource represents a Web service, you may want to assign it a unique bit for use in the f_ResourceFlags bit field (the bits from &H00020000 and greater are available for your use). If your address resource is a Web service instead of a Web site, you will want to set the Web service bit (&H00000400) to keep the cache refresh functionality from unintentionally issuing a cache refresh request to your Web service. For more information about hooking your address resource into the cache refresh functionality, see Refreshing Caches for an Address Resource.

    In the following sample code, the variable myOwnWebServiceBit is set to zero (0), indicating that address resource being created is a Web site, not a Web service. The f_ResourceFlags basic property is set to the value &H0000000A, which is a combination of bits &H00000002 and &H00000008. This indicates that the resource should be displayed within Commerce Server Manager, and that it is an address resource. This resource is displayed in the Applications node in the corresponding site node in the Commerce Sites node.

  • When you get or set address resource extended properties that have a data type of "array of strings", you must use the special methods of the configuration objects that are designed to correctly get and set these values. These methods begin with "Make", such as the MakeStringFromArray method.

    In order to use these special methods from Visual Basic Scripting Edition code, you must instantiate an unmanaged COM configuration object, such as the GlobalConfig2 object, as a helper object through which you can access these methods. The following example code demonstrates this technique in three places where setting multiple values for the extended properties s_WebServerMachine, s_WebServerName, and s_IPPort.

  • You should set the value of the s_NumberOfServers extended property to the number of values that you supply to the various multivalued extended properties, such as s_WebServerMachine, s_WebServerName, and s_IPPort as shown in this sample.

Dim varWebServerMachine(1), varWebServerName(1), varIPPort(1)
Dim siteConfig, siteConfigHelper
Dim myOwnWebServiceBit

Set siteConfigHelper = CreateObject("Commerce.GlobalConfig2")

Set siteConfig = CreateObject("Microsoft.CommerceServer.Interop.Configuration.SiteConfigFreeThreaded")
siteConfig.Initialize ("MyCommerceSite")

siteConfig.CreateComponentConfig "MyAddressResource", "MSCS_Address"

siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("s_VirtualRootName").Value = "MySite"

siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("s_ProgIDPUP").Value = "Commerce.AddressPuP"

myOwnWebServiceBit = 0
if myOwnWebServiceBit > 0 then
    siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("f_ResourceFlags").Value = _
        siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("f_ResourceFlags").Value Or _
                                                                                    &H00000400 Or _
                                                                                 myOwnWebServiceBit
end if

siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("f_EnableHTTPS").Value = 0

varWebServerMachine(0) = "MyWebServerMachine1"
varWebServerMachine(1) = "MyWebServerMachine2"
siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("s_WebServerMachine").Value = _
                                           siteConfigHelper.MakeStringFromArray(varWebServerMachine)

varWebServerName(0) = "MyWebServerName1"
varWebServerName(1) = "MyWebServerName2"
siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("s_WebServerName").Value = _
                                           siteConfigHelper.MakeStringFromArray(varWebServerName)

varIPPort(0) = "80"
varIPPort(1) = "80"
siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("s_IPPort").Value = _
                                           siteConfigHelper.MakeStringFromArray(varIPPort)

siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("s_NumberOfServers").Value = 2
siteConfig.Fields.Item("MyAddressResource").Value.Fields.Item("s_CurrentServer").Value = 0

siteConfig.SaveConfig

See Also

Other Resources

Creating an Instance of a Custom Resource

Resource Tables in the Administration Database

Refreshing Caches for an Address Resource

Working with Address Resources