Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1148
  • Last Modified:

Use of COM Objects in Web Service

Does anyone know if it is possible to use COM objects in a Web Service

If posible, is there any specific way that i will have to create the COM object or register it differently ?

I have tried using a COM object in a web Service but I get an Access Violation when i call CreateOLEObject.

When i use the exact same code in a normal Win32 Application, it works perfectly.

I am writing a Win32 SOAP Web Service and i am using Delphi 2007 Profesional

I have attached the function that returnes the Access Violation. The line on which the AV occurs is the line:
esw := CreateOLEObject('postilion.ESocketWeb');

function DoBalanceEnquiry(ACardNo : WideString; AInstitution: Integer;
  ACurrency : integer; out AResponse : TStringLIst): Integer;
var
  esw : Variant;
  esw_BalanceEnquiry : Variant;
  esw_BalanceEnquiry_Rsp : Variant;
  esw_Identification : Variant;
  esw_DateTime : Variant;
  esw_Card : Variant;
  esw_Financial : Variant;
  esw_Transaction_Fee : Variant;
  esw_Routing : Variant;
  esw_Merchant : Variant;
 
  sResponseCode, sCFGName : WideString;
  iLastCheckPoint : Integer;
begin
  Result := 0;
  AResponse := TStringList.Create;
 
  sCFGName := ExtractFilePath(GetModuleName) + 'esocketweb.cfg';
  try
    esw := CreateOLEObject('postilion.ESocketWeb');
    esw.initialize(sCFGName);
    esw.connect;
    if not esw.isConnected then
      Result := 500
    else begin
      esw_BalanceEnquiry := esw.newBalanceInquiry;
 
      esw_Identification := esw_BalanceEnquiry.newIdentification;
 
      esw_Card := esw_Identification.newCard;
      esw_Card.setCardNumber(ACardNo);
 
      esw_Financial := esw_BalanceEnquiry.newFinancial;
 
      esw_Transaction_Fee := esw_Financial.newTransactionFee;
      esw_Transaction_Fee.setCurrency(IntToStr(ACurrency));
      esw_Transaction_Fee.setAmount('0');
      esw_Transaction_Fee.setDebitCredit('D');
 
      esw_DateTime := esw_BalanceEnquiry.newDateTime;
      esw_DateTime.setYear(formatdatetime('yyyy',now));
      esw_DateTime.setMonth(formatdatetime('mm',now));
      esw_DateTime.setDay(formatdatetime('dd',now));
      esw_DateTime.setHour(formatdatetime('hh',now));
      esw_DateTime.setMinute(formatdatetime('mm',now));
      esw_DateTime.setSecond(formatdatetime('ss',now));
 
      esw_Merchant := esw_BalanceEnquiry.NewMerchant;
      esw_Merchant.setId(IntToStr(AInstitution));
 
      esw_Routing := esw_BalanceEnquiry.newRouting;
      esw_Routing.setAcquiringInstitution(IntToStr(AInstitution));
 
      esw_BalanceEnquiry_Rsp := esw.send(esw_BalanceEnquiry);
 
      sResponseCode := esw_BalanceEnquiry_Rsp.getResponse.getResponseCode;
      AResponse.Add('00=' + sResponseCode);
      if sResponseCode = '00' then
      begin
        AResponse.Add('01=' + esw_BalanceEnquiry_Rsp.getBalanceList.getBalance('ledger_balance').getAmount); // Ledger Balance
        AResponse.Add('02=' + esw_BalanceEnquiry_Rsp.getBalanceList.getBalance('available_balance').getAmount); // Available Balance
      end;
    end;
  except
    on e:exception do
    begin
      LastCheckpoint := iLastCheckPoint;
      LastFunction := 'uDTPostilion.DoBalanceEnquiry';
      LastException := e;
      Result := -1;
    end;
  end;

Open in new window

0
jeboersema
Asked:
jeboersema
  • 5
  • 3
  • 3
1 Solution
 
sumitkchawlaCommented:
Check if the credentials with which your App Domain is running has permissions to Create COM objects.
0
 
developmentguruCommented:
You may need to call CoInitialize and CoUninitialize on your own.  Main Delphi apps do this for you.

Let me know if this helps, or if you need more.
0
 
jeboersemaAuthor Commented:
Dear sumitkchawla

You said: "Check if the credentials with which your App Domain is running has permissions to Create COM objects."

How can I determine what the App Domain currently is and how do i go about changing the permissions ?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jeboersemaAuthor Commented:
Dear developmentguru

Where in the Web Service would i have to call CoInitialize and CoUninitialize ?

Do you perhaps have an example at hand to illustrate this.
0
 
sumitkchawlaCommented:
In the IIS settings you can right click on your App Domain and can verify the username password under credentials section
0
 
developmentguruCommented:
The only important point is that the coinitialize is called befor you attempt to invoke and use your COM object.  This can be done immediately before (with a finally section to uninitialize it).  I would think the preferred way would be on initialization of your web service with the CoUninitialie being done when the seb service is unloaded.  If you need more, I will try to set up a demo project.  Let me know.
0
 
jeboersemaAuthor Commented:
Dear developmentguru

I have tried calling CoInitialize, but now it still fails but without any exception message.

Could you please provide an example of how this could be achieved successfully ?
0
 
jeboersemaAuthor Commented:
Dear sumitkchawla

I have looked at the articles you refer to but they have no bearing on this issue as i am not developing a webservice in .NET.

It is a Win32 WebService that is using a COM object. (Or that is the objective if i can get it to work.)

I am deploying on IIS7 and i am not exactly sure where to set the AppDomain's credentials.
0
 
developmentguruCommented:
 Your SOAP web service, is it ISAPI or CGI?  I believe I have used ISAPI in the past... I have created a simple COM object (called SimpleAdder) to use in testing this and created a simple Delphi application to test the COM object.  It is important that I know which type of web service you are creating so I can answer the question the way you need it answered.  I would hate to put together 4 projects only to find out that it is not what you  were looking for.

  I suspect that what you are facing is a compound error.  The first part was initializing the COM interface.  The second part is an error in instantiating the object itself.  This could have to do with an incompatible threading model... I am throwing out a guess there.  The point is that you may want to create a simple COM object to test with and see if you can get that to work first.  If that works and the original does not then you have more information to go on.

Let me know.
0
 
jeboersemaAuthor Commented:
I am writing an Win32 ISAPI SOAP Web Service

After i have made a call to CoInitialize, it still fails but now there is no exception message.

I am starting to think that it has something to do with the threading model.

Thanx for all the help.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now