Solved

Any ideas on this Win32 OLE 1403 error?

Posted on 2004-09-28
8
810 Views
Last Modified: 2012-05-05
A client received the following error the other day when submitting some form data:

Win32::OLE(0.1403) error 0x80072ee2
    in METHOD/PROPERTYGET "send" at d:\docs\wcsuggest\wcSuggestAction.pl line 138
OLE exception from "msxml4.dll":

This method cannot be called until the send method has been called.

Win32::OLE(0.1403) error 0x80020009: "Exception occurred"
    in METHOD/PROPERTYGET "responseText" at d:\docs\wcsuggest\wcSuggestAction.pl line 139
Content-Type: text/html; charset=ISO-8859-1


I've never received this error in testing nor have any other clients reported it, and I'm not sure what to do about it. Can anyone provide some insight into this? Is it just one of those things? Was IIS perhaps too busy or something else at the time of submission?

Here's line 138 from the script:

    $xmlhttp->send($xml);

Which is part of the following sub:

sub submitWpXml {
    my $xml = shift;
    my $xmlhttp = Win32::OLE->new('MSXML2.ServerXMLHTTP.4.0');
    my $sServerName = 'this.here.com';
    # $ENV{'SERVER_NAME'} || 'localhost';

    $xmlhttp->open('POST', "http://$sServerName/dbtw-wpd/exec/dbtwpcgi.exe", "false", "", "" );
    $xmlhttp->setRequestHeader('Content-type', 'text/xml');
    $xmlhttp->send($xml);
    return $xmlhttp->{responseText}; ### this is a property.
}

Here's the entire wcSuggestAction script:

#!/usr/bin/perl -w

use strict;
use CGI;
use Win32::OLE;
use XML::Twig;
use HTML::Template;
use Time::Format qw(%time %strftime %manip);
use URI::Escape qw(uri_unescape);
use URI::Escape qw(uri_escape);


$ENV{'HTML_TEMPLATE_ROOT'} = "/docs";

#==================================================
#GLOBAL Variables
#==================================================

my $queryError;  #//queryError holds an error generated for display

# //variables for writing response messages
my( $strAc, $strSucceeded, $strFailed, $strStatus, $strRecResult, $entrySeparator, $objNode, $objWpResponse);
my( $strAC, $intSucceeded, $intFailed, $objRecProcNode, $objIndvRecProcNode, $strXmlInput, $strXmlReturnedXml);
my $strRecInfo = '';

# // for display of Debug
my( $strXmlOutput, $sServerName);

## print standard http header
my $query = new CGI;
print $query->header;

my $UniqueID = $query->param('UniqueID');
my $firstName = $query->param("firstName");
my $lastName = $query->param("lastName");
my $email = $query->param("email");
my $SiteName = $query->param("site_name");
my $SiteUrl = $query->param("site_url");
my $CorpDivision = $query->param("corp_division");
my $SiteContact = $query->param("site_contact");
my $RegRequired = $query->param("site_registration");
my $UpdateFrequency = $query->param("update_frequency");
my $SiteDescription = $query->param("description");
my $Keywords = $query->param("Keywords");
$SiteDescription =~ s/\r\n/\n/g;  #without this global substitution, site_description
                                  #is not returned properly
my $Status = $query->param("Status");


# /* 1. Build the XML Query with the buildWpQuery function */
$strXmlInput = buildWpQuery();

# /* 2. Send the XML Query to WP Pro and get the XML Response
#   from WP Pro to the XML Query */
my $strReturnedXml = submitWpXml($strXmlInput);

# /* 3. Process The XML returned by WP Pro. This will place the
#the information extracted from the WP Pro response in variables */
processWpXml($strReturnedXml);


#Output return page or debugging page
printYourOutputHere();

#send email alert to Information Development
doSendID();

#send email confirmation to client
doSendClient();


####### End of program. Subroutine implementation follows

#we use "update" instead of "insert" just in case a user finds a way to back in and resubmit

sub buildWpQuery {
    my $xml = "<?xml version=\"1.0\" ?>\n" .
                   "<Query xmlns=\"http://www.inmagic.com/webpublisher/query\">\n" .
                   "<AC matchFound=\"replaceRecord\" matchNotFound=\"acceptRecord\">update</AC>\n" .
                   "<TN>wcSuggest</TN>\n" .
                   "<MatchFields>\n" .
                   "<MatchField>UniqueID</MatchField>\n" .
                   "</MatchFields>\n" .
                   "<KeyFields>\n" .
                   "   <KeyField>UniqueID</KeyField>\n" .
                   "   <KeyField>FirstName</KeyField>\n" .
                   "   <KeyField>LastName</KeyField>\n" .
                   "</KeyFields>\n" .
                   "<Recordset>\n" .
                   "   <Record>\n" .
                   "      <UniqueID><![CDATA[".$UniqueID."]]></UniqueID>\n" .
                   "      <FirstName><![CDATA[".$firstName."]]></FirstName>\n" .
                   "      <LastName><![CDATA[".$lastName."]]></LastName>\n" .
                   "      <Email><![CDATA[".$email."]]></Email>\n" .
                   "      <SiteName><![CDATA[".$SiteName."]]></SiteName>\n" .
                   "      <SiteUrl><![CDATA[".$SiteUrl."]]></SiteUrl>\n" .
                   "      <CorpDivision><![CDATA[".$CorpDivision."]]></CorpDivision>\n" .
                   "      <SiteContact><![CDATA[".$SiteContact."]]></SiteContact>\n" .
                   "      <RegistrationRequired><![CDATA[".$RegRequired."]]></RegistrationRequired>\n" .
                   "      <UpdateFrequency><![CDATA[".$UpdateFrequency."]]></UpdateFrequency>\n" .
                   "      <SiteDescription><![CDATA[".$SiteDescription."]]></SiteDescription>\n" .
                   "      <RequestDate><![CDATA[".$time{'mm/dd/yyyy H:mm:ss PM'}."]]></RequestDate>\n" .
                   "      <Status><![CDATA[".$Status." (submitted ".$time{'mm/dd/yyyy H:mm am'}.")]]></Status>\n";

        $xml .=           makeMultiple($query->param("Keywords"));

        $xml .=    "   </Record>\n</Recordset>\n</Query>";
    return $xml;

}

sub makeMultiple {
   my $string = shift;
   my @members = split(/\,/,$string);

   my $cat_store;

foreach my $mM(@members) {
       $cat_store .= "      <Keywords><![CDATA[".$mM."]]></Keywords>\n"; #as above, need to store
}                                                                        #result first and then
  return $cat_store;                                                     #return it!
}


sub submitWpXml {
    my $xml = shift;
    my $xmlhttp = Win32::OLE->new('MSXML2.ServerXMLHTTP.4.0');
    my $sServerName = 'this.here.com';
    # $ENV{'SERVER_NAME'} || 'localhost';

    $xmlhttp->open('POST', "http://$sServerName/dbtw-wpd/exec/dbtwpcgi.exe", "false", "", "" );
    $xmlhttp->setRequestHeader('Content-type', 'text/xml');
    $xmlhttp->send($xml);
    return $xmlhttp->{responseText}; ### this is a property.
}

sub processWpXml {
     my $xml =  shift;
     eval {
          my $twig = XML::Twig->new();
          $twig->parse($xml);
          my $errorNode = $twig->first_elt('inm:Record-Error');

          # //read attributes from the Records-Processed in global vars
          $objRecProcNode = $twig->first_elt('inm:Records-Processed');
          $strAC = $objRecProcNode->{'att'}->{'AC'};
          $intSucceeded   = $objRecProcNode->{'att'}->{'succeeded'};
          $intFailed      = $objRecProcNode->{'att'}->{'failed'};

          if($intSucceeded > 0) {$strStatus = "succeeded."};
          if($intFailed > 0) {$strStatus = "failed."};

          # //Get Result attribute of the first record processed.
          $objIndvRecProcNode = $twig->first_elt('inm:Record-Processed');
          $strRecResult = $objIndvRecProcNode->{'att'}->{"result"};




          if($errorNode) {
               $queryError = $errorNode->text;
          }

          foreach my $objNode( $twig->find_nodes('/inm:Results/inm:Records-Processed/inm:Record-Processed/*') )
               {
                $strRecInfo .= '<b>' . $objNode->tag . ':</b> ';
                $strRecInfo .= $objNode->text . '<br/>';
                $strRecInfo =~ s/inm://;
               }



          };
}

sub doSendID {

## PERL module to read the HTML form variables into PERL
use CGI;
$query=new CGI;

my $target_acct='person.1@here.com';

use URI::Escape qw(uri_unescape);
use MIME::Lite;
use Net::SMTP;


### Adjust sender, recipient and your SMTP mailhost
my $from_address = to.address@here.com';
my $to_address = $target_acct;
my $mail_host = 'hub.here.com';
my $cc_address = 'person2@here.com';
my $bcc_address = 'person3@here.com';

#use Time::Format qw(%time %strftime %manip);

## Adjust line breaks in feedback
$SiteDescription=~s/<BR>\n/\n/g;

### Adjust subject and body message; build link to feedback and send to Information Development
my $subject = 'Webcat Suggestion: '.$lastName.
               ', '.$firstName.' '.
               $time{'yyyy-mm-dd H:mm am'};
my $message_body = <<"EMAIL";
Name: $firstName $lastName
Email: $email
Site Url: $SiteUrl

View this suggestion at:
http://this.here.com/dbtw-wpd/exec/dbtwpcgi.exe?XC=%2Fdbtw-wpd%2Fexec%2Fdbtwpcgi.exe&BU=http%3A%2F%2Fthis.here.com&TN=wcSuggest&DL=0&RL=0&NP=0&RF=IDReview&MR=1&AC=QBE_QUERY&MF=&QY=find+uniqueid%3D$UniqueID
EMAIL

### Create the multipart container

my $msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
  Cc => $cc_address,
  Bcc => $bcc_address,
  Subject => $subject,
  Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part
$msg->attach (
  Type => 'TEXT',
  Data => $message_body
) or die "Error adding the text message part: $!\n";

### Send the Message
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;

}

sub doSendClient {

############Send different version to client
### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'person@here.com';
my $mail_host = 'hub.here.com';
my $to_address = $query->param('email');

### Adjust subject and body message; send a pretty confirmation message to the client
my $subject = 'Catalog Suggestion - Confirmation';
my $sServerName = $ENV{'SERVER_NAME'} || 'localhost';

my $message_bodyB = <<"EMAIL";
<IMG src="http://$sServerName/images/ic_banner_plain.gif" border="0" width="616" height="112" usemap="#Map">
  <MAP name="Map">
    <AREA shape="rect" coords="0,0,545,114" href="http://ic.here.com">
    <AREA shape="rect" coords="543,0,622,114" href="http://home.here.com">
  </MAP>
Thank you $firstName. We have received your suggestion.
<BR><HR>
EMAIL

$SiteName ? $message_bodyB .= 'Site Name: <font color="green">' . $SiteName ."</font>": "";

$SiteUrl ? $message_bodyB .= '<P>Site Url: <font color="green">' . $SiteUrl ."</font></P>": "";

$CorpDivision ? $message_bodyB .= '<P>Corporate Division: <font color="green">' . $CorpDivision ."</font></P>": "";

$SiteContact ? $message_bodyB .= '<P>Site Contact: <font color="green">' . $SiteContact ."</font></P>": "";

$RegRequired ? $message_bodyB .= '<P>Registration requirement: <font color="green">' . $RegRequired ."</font></P>": "";

$UpdateFrequency ? $message_bodyB .= '<P>Update Frequency: <font color="green">' . $UpdateFrequency ."</font></P>": "";

$Keywords ? $message_bodyB .= '<P>Keywords: <font color="green">' . $Keywords ."</font></P>": "";

$SiteDescription ? $message_bodyB .= '<P>Description: <font color="green">' . $SiteDescription ."</font></P>": "";

$message_bodyB .= "<HR><P>If we have any questions, we will contact you.</P><P>Regards,</P><P>Information Center, New York</P><P>&nbsp;</P>";


$message_bodyB=~s/\n/<BR>\n/g;

$message_bodyB = "<table width='500'><tr><td><font face='Arial' size='3'>".$message_bodyB."</font></td></tr></table>";
### Create the multipart container

my $msg = MIME::Lite->new (
  From => $from_address,
  To => $to_address,
  Subject => $subject,
  Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part
  $msg->attach (
  Type => 'text/html',
  Data => $message_bodyB
) or die "Error adding the text message part: $!\n";

### Send the Message

MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;

}


sub printYourOutputHere {
# open the HTML template
my $template = HTML::Template->new(filename => '/wcSuggest/wcSuggestReturn.tmpl');  #switch off for debugging
#my $template = HTML::Template->new(filename => '/wcSuggest/debug.tmpl');          #switch on for debugging
$SiteDescription=~s/\n/<BR>\n/g;                    #the return page
$template->param(FIRSTNAME => $firstName);           #the return page
$SiteName ? $template->param(SITENAME => 'Site Name: <font color="green">' . $SiteName . "</font>") : "";#the return page
$template->param(SITEURL => 'Url: <font color="green">' . $SiteUrl . "</font>"); #the return page
$CorpDivision ? $template->param(CORPDIV => 'Division: <font color="green">' . $CorpDivision . "</font>") : "";#the return page
$SiteName ? $template->param(SITECONTACT => 'Site Contact: <font color="green">' . $SiteContact . "</font>") : ""; #the return page
$RegRequired ? $template->param(REGREQUIRED => 'Registration: <font color="green">' . $RegRequired . "</font>") : ""; #the return page
$UpdateFrequency ? $template->param(UPDFREQUENCY => 'Update Frequency: <font color="green">' . $UpdateFrequency . "</font>") : ""; #the return page
$Keywords ? $template->param(KEYWORDS => 'Keywords: <font color="green">' . $Keywords . "</font>") : "";             #the return page
$SiteDescription ? $template->param(DESCRIPTION => 'Description: <font color="green">' . $SiteDescription . "</font>") : ""; #the return page

print $template->output;

}


0
Comment
Question by:GessWurker
  • 4
8 Comments
 
LVL 12

Accepted Solution

by:
geotiger earned 250 total points
ID: 12171198
Will you be able to re-produce the error? Could you add the debug in the line as this

$xmlhttp->send($xml) or print  Win32::OLE->LastError();


----------------------------
Win32::OLE->LastError()

The LastError() class method returns the last recorded OLE error. This is a dual value like the $! variable: in a numeric context it returns the error number and in a string context it returns the error message. The error number is a signed HRESULT value. Please use the HRESULT(ERROR) function to convert an unsigned hexadecimal constant to a signed HRESULT.
The last OLE error is automatically reset by a successful OLE call. The numeric value can also explicitly be set by a call (which will discard the string value):

        Win32::OLE->LastError(0);
0
 

Author Comment

by:GessWurker
ID: 12171229
Never encountered the error before and don't know how I could reproduce it.
0
 
LVL 18

Assisted Solution

by:kandura
kandura earned 250 total points
ID: 12173011
The funny thing is that this error message seems to be telling you that you can not call this method before calling this method. ;^)
I'd guess that this truly is an exception, and not really worth investing a lot of time in.
At first, just keep an eye on how often it occurs, and if it turns out to be a freak accident, just live with it.

You could wrap the "send" call in an eval block to catch any exception like this:

    eval {
        $xmlhttp->send($xml);
    };
    if($@) {
        # perform error handling here
    }
   
That way the flow of your program is not interrupted, and you get a chance to report the error (stored in $@) -- by e-mail for example -- and present the user with a friendly message.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:GessWurker
ID: 12173131
kandura:

Thanks for your response. Fortunately, the time-out didn't prevent the rest of the script from running, it just prevented the xml insert from occurring. The client got his "thank you for your submission letter" and we got the email letting us know somebody'd just submitted something. It's just that the link included in our email that should have taken us directly to the new database entry came up with no results (since no xml insert occurred). In any event, I was able to get all the info the user intended to send by looking at the IIS log and parsing out the appropriate "GET".

I'm going to modify the email alert we get so that it includes all the information the client submits, not just a link to the database entry that contains all that submitted info.

I'll let you all know if this strange time-out occurs again in the near future.
0
 

Author Comment

by:GessWurker
ID: 12532171
The error has not occurred (as far as I know) since the time I initially reported it. OK if I split the points between the folks who tried to help?
0
 

Author Comment

by:GessWurker
ID: 12532998
Sorry for the delay. I'll split up the points.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now