Yes both methods are running parallel and embedded SQL and object access are combined. My question is  object oid of a row is stored inmemory.  When you do some operation with embedded SQL the updated disk data is not updated automatically in the inmemory object. Means the open I'd should be explicitly reloaded to get the latest data from row.

The real question is whether I should kill the object oid then open it or don't kill the open Id object and just do the reload.

Well my question has to scoped within object script. Trying to find the way. How about creating the request using  %XML.Writer.

Expected Output for class 'Myclass'

Class User.Myclass
{

Property Username As %String;

Property Password As %String;
 
}

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
        <Myclass xmlns="http://www.xyz.com/test">
            <Username>123</Username>
            <Password>123</Password>
        </GetSecurityToken>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

To make it more clear, I've a REST service which takes 'SOAP Request' in it's body and forward the request to SOAP endpoint. Now I have to call this service where I need to frame a SOAP envelope. I created the SOAP client and it can call only SOAP service(end point is a class with SOAP webmethod class). But in this case a SOAP envelop needs to be created to pass it to REST's POST.

You can try referring the multiple jar files as list to  gateway.

Set AssemblyFileNameWithPath1="jar path 1" 

Set AssemblyFileNameWithPath2="jar path 2"
 Set gateway=##class(%Net.Remote.Gateway).%New()
 Set classpath=##class(%ListOfDataTypes).%New()
  Dclasspath.Insert(AssemblyFileNameWithPath1)

Dclasspath.Insert(AssemblyFileNameWithPath2)
 Set status=gateway.%Connect(Host,Port,NameSpace,10,classpath)

Add the reference to cache provider for .net

using InterSystems.Data.CacheClient;


CacheDataReader dr;

using (CacheConnection con = new CacheConnection())
   {
             con.ConnectionString = "Server=" + Servername+ ";" + "Port=1972; Namespace=Namespace;" + "Password=" + Password + ";" + "User ID=" + UserName + ";";

             CacheCommand cmd;
             cmd = new CacheCommand("select * from table", con);
              con.SetQueryRuntimeMode(InterSystems.Data.CacheTypes.QueryRuntimeMode.DISPLAY);
              con.Open();
              dr = cmd.ExecuteReader();
             while (dr.Read()){ // do your stuff }
}

I've tried using intersystems provider for jdbc and it's work fine. Below is the sample.

import com.intersys.jdbc.CacheDataSource;
//C:\InterSystems\HealthShare\dev\java\lib\JDK18\cache-jdbc-2.0.0.jar

public class Assignment {

    public static void main(String[] args) {
        
            ConnectionString = "jdbc:Cache://" + localhost+ ":" + 1972+ "/" + "SYS";
            CacheDataSource ds = new CacheDataSource();
            ds.setURL(ConnectionString);
            ds.setUser(UserId);
           ds.setPassword(Password);

            System.out.println("Connecting to  db....");
            java.sql.Connection dbconnection = ds.getConnection();
            java.sql.Statement stmt = dbconnection.createStatement();

            System.out.println("Fetching Data from db....");
            String sqlQuery = "SELECT * from table";
            ResultSet rs = stmt.executeQuery(sqlQuery );
    }

}

Task Type in UI is nothing but the Class in which you are wrapping your code.

Class Task.Classname  Extends %SYS.Task.Definition

{

Set tSC ##class(Ens.Director).CreateBusinessService("service name",.tService)

If ($IsObject(tService)) {
   Set input ##class(service class??).%New()
   Set input.Value = 22
   Set tSC tService.ProcessInput(input,.output

}

}

  ClassMethod  Createtask() As %Status
{

Set tStatus = $$$OK
Try 
{

Set tTaskName = "Task Name"
Set tTaskClass = "Task.Classname"
Set tTaskDesc = "Task Desc"

Set tSql="select ID from %SYS.Task where NameSpace = ? and TaskClass = ?"
Set tRS = ##class(%SQL.Statement).%ExecDirect(,tSql, $Namespace, tTaskClass)
If (tRS.%Next())
{
 "Updating Task: "_tTaskName
Set tTaskObj = ##class(%SYS.Task).%OpenId(tRS.ID)
}
Else 
{
"Creating Task: "_tTaskName
Set tTaskObj = ##class(%SYS.Task).%New()
}

Set tTaskObj.NameSpace = $Namespace
Set tTaskObj.Name = tTaskName
Set tTaskObj.TaskClass = tTaskClass
Set tTaskObj.Description = tTaskDesc
Set tTaskObj.RunAsUser = "_system"
//Run task daily at 2 am
Set tTaskObj.TimePeriod = tTaskObj.TimePeriodDisplayToLogical("Daily")
Set tTaskObj.TimePeriodEvery = 1 // Every day (7 days a week)
Set tTaskObj.DailyFrequency = tTaskObj.DailyFrequencyDisplayToLogical("Once") // Run once daily
Set tTaskObj.DailyStartTime = (60*60*2) // 2:00am

"Saving task"
Set tStatus = tTaskObj.%Save()
$$$ThrowOnError(tStatus)

"Saved task ID: "_tTaskObj.%Id()

Do $SYSTEM.Task.Resume(tTaskObj.%Id())
 
}
Catch ex {
Set tStatus = ex.AsStatus()
}
Quit tStatus
}