Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on project of silverlight WCF application .I want to upload the data in xml format in specific URL . data is coming from WCF service output.

so please help me .
Thanks

I am putting my code here

in Iservice1.cs
-----------------------------------------------------------------------------------
[OperationContract]
List<accountdetail> GetAccountList();
-----------------------------------------------------------------------------------
In Service1.svc.cs


public List<accountdetail> GetAccountList()
{
List<accountdetail> lstClient = new List<accountdetail>();

try
{
Conn.Open();

SqlCommand Cmd = new SqlCommand("SalesforceIntegrator.dbo.[SF_getAccountDetails]", Conn);
Cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader Reader = Cmd.ExecuteReader();

while (Reader.Read())
{
lstClient.Add(new AccountDetail()
{
iInsightAccountID = Convert.ToInt32(Reader[0]),
CustodianAccountNumber = Reader[1].ToString(),
AccountName = Reader[2].ToString(),

});
}
Reader.Close();
}
catch (Exception ex)
{
ex.InnerException.Message.ToString();
throw ex;
}
finally
{
Conn.Close();
}
return lstClient;

}

--------------------------------For buttom click-------------------

private void GetBtn_Click(object sender, RoutedEventArgs e)
{ svc.GetAccountListCompleted += new EventHandler<servicereference1.getaccountlistcompletedeventargs>(svc_GetAccountListCompleted);
svc.GetAccountListAsync();
}

void svc_GetAccountListCompleted(object sender, ServiceReference1.GetAccountListCompletedEventArgs e)
{
dataGrid1.ItemsSource = e.Result;
System.Collections.ObjectModel.ObservableCollection<clientsilverlightapplication.servicereference1.accountdetail> lstClient = new System.Collections.ObjectModel.ObservableCollection<clientsilverlightapplication.servicereference1.accountdetail>();

lstClient = e.Result;

WebClient client = new WebClient();
//client.Headers["Content-type"] = "application/json";

//DataContractSerializer

DataContractSerializer serializer = new DataContractSerializer(lstClient.GetType());
MemoryStream Stream = new MemoryStream();
serializer.WriteObject(Stream, lstClient);
byte[] bytes = Stream.ToArray();
Uri uri = new Uri("https://360-dynamicwealthadvisors.cs14.force.com/services/apexrest/JsonService");

//For Upload theData
client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
client.UploadStringAsync(uri, "POST", Stream.ToString());

MessageBox.Show(Convert.ToString(bytes));

Stream = new MemoryStream(bytes);
//display(Stream);
//byte[] array = Encoding.Unicode.GetBytes(Stream);
MessageBox.Show("successfully Upload");
}
Posted

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



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