Click here to Skip to main content
15,919,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an order table which have OrderNo,OrderDesc,OrderDate,OrderQuantity,OrderCreationDate,CreatedBy fields. I need to generate orders as XML file and send them a folder. How can I do that using windows service ?
 If windows service successfully executes the file, move XML file to "Successed" folder
 • If windows service does not execute the file for any reason, move XML file to "Failed" folder


What I have tried:

I generated a windows service , constructed a database and table which name is orders. And connected the service to my database.
Posted
Updated 30-Jan-22 13:28pm

1 solution

What have you tried so far? There is a Dot Net API for converting to/from classes & raw XML.

This Google search has many examples to point you in the right direction.
 
Share this answer
 
Comments
goztepeli 31-Jan-22 16:12pm    
Thanks for your answer @Graeme_Grant . I m searching it. I need to convert my orders to xml file.And send it input folder .


my windows service code:

namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public Service1()
{
ConnectToDb();
}
SqlConnection conn;
SqlCommand comm;

SqlConnectionStringBuilder connectionStringBuilder;

void ConnectToDb()
{
connectionStringBuilder = new SqlConnectionStringBuilder();
connectionStringBuilder.DataSource = "LAPTOP-S1JS05JQ\\SQLEXPRESS";
connectionStringBuilder.InitialCatalog = "ATS";
connectionStringBuilder.Encrypt = true;
connectionStringBuilder.TrustServerCertificate = true;
connectionStringBuilder.ConnectTimeout = 500;
connectionStringBuilder.AsynchronousProcessing = true;
connectionStringBuilder.MultipleActiveResultSets = true;
connectionStringBuilder.IntegratedSecurity = true;

conn = new SqlConnection(connectionStringBuilder.ToString());
comm = conn.CreateCommand();

}


public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}

public int InsertOrder(Order o)
{
try
{
comm.CommandText = "INSERT INTO Orders VALUES(@OrderNo,@OrderDesc,@OrderDate,@OrderQuantity,@OrderCreationDate,@CreatedBy)";
comm.Parameters.AddWithValue("OrderNo", o.OrderNo);
comm.Parameters.AddWithValue("OrderDesc", o.OrderDesc);
comm.Parameters.AddWithValue("OrderDate", o.OrderDate);
comm.Parameters.AddWithValue("OrderQuantity", o.OrderQuantity);
comm.Parameters.AddWithValue("OrderCreationDate", o.OrderCreationDate);
comm.Parameters.AddWithValue("CreatedBy", o.CreatedBy);
comm.CommandType = System.Data.CommandType.Text;
conn.Open();
return comm.ExecuteNonQuery();
}
catch (Exception)
{

throw;
}
finally
{
if (conn != null)
{
conn.Close();
}
}
}

}
}



My desktop app code :

private void button1_Click(object sender, EventArgs e)
{
Order o = new Order();
o.OrderNo = Convert.ToInt32(OrderNo.Text);
o.OrderDesc = OrderDesc.Text;
o.OrderDate = DateTime.Now.Date;
o.OrderQuantity = Convert.ToInt32(OrderQuantity.Text);
o.OrderCreationDate = DateTime.Now.Date;
o.CreatedBy = CreatedBy.Text;
Service1Client service = new Service1Client();
if(service.InsertOrder(o)==1)
{
MessageBox.Show("Order Created Successfully");
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900