Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling WCF Webservice from Excel VBA using GetObject() method
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/1013428/how-do-i-call-wcf-client-from-excel-2003-vba">How do I call WCF client from Excel 2003 VBA?</a> </p> </blockquote> <p>I want to call a web service developed using WCF from the Excel using VBA code. How can we do this ? I have tried the <code>GetObject()</code> method but I'm getting syntax error while using this. I want to display the data that I'm getting from the web service in Excel. Please help. The DataContract is as follows: `</p> <pre><code>[DataContract] public class Data { [DataMember] public int Id; [DataMember] public DateTime LockTime; [DataMember] public DateTime LoginTime; [DataMember] public DateTime LastDefenitionDate; [DataMember] public string NTLogin; [DataMember] public string SystemName; } </code></pre> <p>ServiceContract is as follows:</p> <p>` </p> <pre><code>[ServiceContract] interface IDataService { [OperationContract] List&lt;Data&gt; GetData(); [OperationContract] void SubmitData(Data data); } </code></pre> <p>`</p> <p>DataService for accessing database is as follows:</p> <p>`</p> <p>[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]</p> <p>public class DataService : IDataService { public static SQLConnection SQLDBConnection = new SQLConnection();</p> <pre><code> #region IDataService Members public List&lt;Data&gt; GetData() { List&lt;Data&gt; datas = new List&lt;Data&gt;(); try { if (SQLDBConnection.con.State == ConnectionState.Closed) SQLDBConnection.con.Open(); datas.Clear(); SqlCommand sqlcommand = new SqlCommand(); sqlcommand.Connection = SQLDBConnection.con; sqlcommand.CommandText = "select * from tblData"; sqlcommand.CommandType = CommandType.Text; SqlDataAdapter sqladapter = new SqlDataAdapter(sqlcommand); DataTable dt = new DataTable(); sqladapter.Fill(dt); Data data = null; for (int i = 0; i &lt; dt.Rows.Count; i++) { data = new Data(); data.Id = Convert.ToInt32(dt.Rows[i]["id"]); data.NTLogin = dt.Rows[i]["NTLogin"].ToString(); data.SystemName = dt.Rows[i]["SystemName"].ToString(); data.LockTime = Convert.ToDateTime(dt.Rows[i]["LockTime"]); data.LoginTime = Convert.ToDateTime(dt.Rows[i]["LoginTime"]); data.LastDefenitionDate = Convert.ToDateTime(dt.Rows[i]["LastDefenitionDate"]); datas.Add(data); } } catch (Exception ex) { } return datas; } public void SubmitData(Data data) { if (SQLDBConnection.con.State == ConnectionState.Closed) SQLDBConnection.con.Open(); SqlCommand sqlcommand = new SqlCommand(); sqlcommand.Connection = SQLDBConnection.con; sqlcommand.CommandText = "Insert into dbo.tblData(NTLogin, SystemName, LockTime, LoginTime, LastDefenitionDate) values ('" + data.NTLogin + "','" + data.SystemName + "','" + data.LockTime + "' , '" + data.LoginTime + "', '" + data.LastDefenitionDate + "')"; sqlcommand.CommandType = CommandType.Text; int RowsAffected = sqlcommand.ExecuteNonQuery(); } #endregion } </code></pre> <p>`</p> <p>EDIT:</p> <p>The <strong>possible duplicate</strong> suggestion's answer didn't worked out for me. My entire code is given here. I have even checked that post, before posting my question. Please check my code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload