Microsoft KB Archive/172214: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - """ to """)
 
Line 48: Line 48:


<ol>
<ol>
<li>Configure the registry to allow ASP to create out-of-process components. For security reasons, ASP by default cannot create out-of-process components. Thus, all attempts to create Transaction Server objects with Server.CreateObject will fail, unless the MTS object is configured to run &quot;In the creator's process&quot; using MTS Explorer. The ASP page will return the following error message to the HTML client:
<li>Configure the registry to allow ASP to create out-of-process components. For security reasons, ASP by default cannot create out-of-process components. Thus, all attempts to create Transaction Server objects with Server.CreateObject will fail, unless the MTS object is configured to run "In the creator's process" using MTS Explorer. The ASP page will return the following error message to the HTML client:
<div class="errormessage">
<div class="errormessage">


Line 110: Line 110:
<li>In Visual Interdev, use the Web Project Wizard to construct a new Web project called MTSWeb. In step two of the wizard, choose to create a new web.</li>
<li>In Visual Interdev, use the Web Project Wizard to construct a new Web project called MTSWeb. In step two of the wizard, choose to create a new web.</li>
<li>In Visual Interdev, create a new Active Server Page file named MTSBank in the MTSWeb project.</li>
<li>In Visual Interdev, create a new Active Server Page file named MTSBank in the MTSWeb project.</li>
<li><p>The new ASP file has a line reading &quot;Insert HTML here.&quot; At that point, insert the following HTML:</p>
<li><p>The new ASP file has a line reading "Insert HTML here." At that point, insert the following HTML:</p>
<pre class="codesample">        <%
<pre class="codesample">        <%
         Dim Accountobj, Msg
         Dim Accountobj, Msg
         If (Not IsNumeric(Request(&quot;Amount&quot;)) _
         If (Not IsNumeric(Request("Amount")) _
             or IsEmpty(Request(&quot;Amount&quot;))) Then
             or IsEmpty(Request("Amount"))) Then
             Msg = &quot;Please enter the amount of the transaction.&quot;
             Msg = "Please enter the amount of the transaction."
         Else
         Else
             set Accountobj = server.createobject(&quot;Bank.Account&quot;)
             set Accountobj = server.createobject("Bank.Account")
             Accountobj.PostVariant Request(&quot;AccountID&quot;), _
             Accountobj.PostVariant Request("AccountID"), _
           Request(&quot;Type&quot;) * Request(&quot;Amount&quot;), Msg
           Request("Type") * Request("Amount"), Msg
         End If%>
         End If%>
         <%=Msg%>
         <%=Msg%>
         <BR>
         <BR>
         <FORM METHOD=&quot;POST&quot; ACTION=&quot;MTSBank.asp&quot;>
         <FORM METHOD="POST" ACTION="MTSBank.asp">
         Transaction Type:
         Transaction Type:
         <INPUT TYPE=&quot;RADIO&quot; NAME=&quot;Type&quot; VALUE=&quot;1&quot; CHECKED>Credit
         <INPUT TYPE="RADIO" NAME="Type" VALUE="1" CHECKED>Credit
         <INPUT TYPE=&quot;RADIO&quot; NAME=&quot;Type&quot; VALUE=&quot;-1&quot; >Debit
         <INPUT TYPE="RADIO" NAME="Type" VALUE="-1" >Debit
         <BR>
         <BR>
         Account ID: <INPUT TYPE=&quot;TEXT&quot; NAME=&quot;AccountID&quot; SIZE=30 VALUE=&quot;1&quot;>
         Account ID: <INPUT TYPE="TEXT" NAME="AccountID" SIZE=30 VALUE="1">
         <BR>
         <BR>
         Amount    : <INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Amount&quot; SIZE=30>
         Amount    : <INPUT TYPE="TEXT" NAME="Amount" SIZE=30>
         <BR>
         <BR>
         <INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;>
         <INPUT TYPE="SUBMIT" VALUE="Submit">
         </FORM>
         </FORM>
                                 </pre></li>
                                 </pre></li>

Latest revision as of 10:05, 21 July 2020

Knowledge Base


How To Invoke MTS Components from Active Server Pages

Article ID: 172214

Article Last Modified on 7/15/2004



APPLIES TO

  • Microsoft Transaction Services 1.0



This article was previously published under Q172214

SUMMARY

To invoke Microsoft Transaction Server (MTS) components from Active Server Pages, (ASP) perform the following three steps, which are described in more detail in the MORE INFORMATION section of this article:

  1. Configure the registry to allow ASP to create out-of-process components. For security reasons, ASP by default cannot create out-of-process components. Thus, all attempts to create Transaction Server objects with Server.CreateObject will fail, unless the MTS object is configured to run "In the creator's process" using MTS Explorer. The ASP page will return the following error message to the HTML client:

    Server object error'ASP 0177:80040154'
    Server.CreateObject Failed

  2. VBScript 2.0 requires that non-Variant data types be passed by value. Therefore, make sure that all non-Variant data types passed by your MTS component are passed by value, not by reference. If you break this rule, the ASP script will return the following error:

    Microsoft VBScript runtime error '800a000d'
    Type mismatch: 'Accountobj.Post'

  3. Write an ASP page that uses Server.CreateObject to create your MTS component.


MORE INFORMATION

  1. If the MTS object is configured to run in an Transaction Server process, the registry must be configured to allow ASP to create out-of-process components. Before changing this registry setting, make sure you have a thorough understanding of how to secure out-of-process components. For example, you should set a specific user identity for the component; otherwise, the MTS component will run under the identity of the first user to access it.

    To allow out-of-process components, use Regedit to select the following key:

          HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3SVC\ASP
          \Parameters
                            

    The Parameters key has several subvalues that control ASP. Make sure it has a subvalue named AllowOutOfProcCmpnts, and that this subvalue is set to 1.

  2. The MTS component may pass only variants by reference; all other data types must be passed by value. The Bank sample supplied with MTS breaks this rule with its Account.Post method, which passes two longs and a string by reference.

    The following steps are instructions for modifying the Bank sample, adding a PostVariant method that has Variant arguments.

    1. Make sure that the Bank package is installed in MTS, and that the Bank Client provided with MTS is able to credit and debit money.
    2. In Visual Basic, open the Account.VB project in the MTX\Samples directory.
    3. Add the code below to the Account class. The new PostVariant method simply wraps the existing Post method.

               Public Function PostVariant(varAccountNo As Variant, _
                  varAmount As Variant, ByRef varResult As Variant) As Variant
                  Dim lngAccountNo As Long
                  Dim lngAmount As Long
                  Dim strResult As String
                  lngAccountNo = varAccountNo
                  lngAmount = varAmount
                  strResult = varResult
                  PostVariant = Post(lngAccountNo, lngAmount, strResult)
                  varAccountNo = lngAccountNo
                  varAmount = lngAmount
                  varResult = strResult
               End Function
                                      
    4. Compile the Bank project. Make sure that the new Vbacct.dll file replaces the copy in the MTX\Packages directory.
    5. In MTS Explorer, select My Computer. On the Tools menu, click Refresh All Components. MTS Explorer should now show that the Bank.Account component has a PostVariant method.
  3. Construct an ASP page that calls the MTS component. Perform the following steps to create an ASP page that manages a bank account by calling the Account.PostVariant method created in step 2 above.

    1. In Visual Interdev, use the Web Project Wizard to construct a new Web project called MTSWeb. In step two of the wizard, choose to create a new web.
    2. In Visual Interdev, create a new Active Server Page file named MTSBank in the MTSWeb project.
    3. The new ASP file has a line reading "Insert HTML here." At that point, insert the following HTML:

               <%
               Dim Accountobj, Msg
               If (Not IsNumeric(Request("Amount")) _
                  or IsEmpty(Request("Amount"))) Then
                  Msg = "Please enter the amount of the transaction."
               Else
                  set Accountobj = server.createobject("Bank.Account")
                  Accountobj.PostVariant Request("AccountID"), _
                Request("Type") * Request("Amount"), Msg
               End If%>
               <%=Msg%>
               <BR>
               <FORM METHOD="POST" ACTION="MTSBank.asp">
               Transaction Type:
               <INPUT TYPE="RADIO" NAME="Type" VALUE="1" CHECKED>Credit
               <INPUT TYPE="RADIO" NAME="Type" VALUE="-1" >Debit
               <BR>
               Account ID: <INPUT TYPE="TEXT" NAME="AccountID" SIZE=30 VALUE="1">
               <BR>
               Amount    : <INPUT TYPE="TEXT" NAME="Amount" SIZE=30>
               <BR>
               <INPUT TYPE="SUBMIT" VALUE="Submit">
               </FORM>
                                      
    4. Save the new ASP file. If you now use a Web browser to access http://YourWebServer/MTSWeb/MTSBank.asp, you will be able to credit or debit money using ASP and the MTS Bank.Account component.


REFERENCES

For more information, visit the Web site at:

Keywords: kberrmsg kbhowto kbsysadmin KB172214