Raman
Raman

Reputation: 41

How to send IList to WCF

How can I send complete IList from application to WCF? Then on the basis of that IList, I want to Save data in Database. For Example:

I have below function in my app.

private IList<Users> UserList() {

}

Now in my WCF i have Below Function

public Void SaveUser(Users U) {

}

Now I want to send whole list of UserList Function from My Application to WCF, and call SaveUser @ WCF.

I can do the whole operation with Loop also by calling SaveUser of WCF withing Loop of my USerList in Application. But due to Performance reasons, I want to avoid this method.

Upvotes: 0

Views: 356

Answers (3)

SaravananArumugam
SaravananArumugam

Reputation: 3720

If I understand it correctly, SaveUser() is a WCF operation contract, and you want to send a list of users to SaveUsers instead of sending them individually.

Edited

Simply send a list of users to the SaveUser method.

public Void SaveUser(List<Users> ul)  {    }

IList is complete supported in WCF.

I hope this helps.

Upvotes: 0

CodingWithSpike
CodingWithSpike

Reputation: 43728

I assume your WCF service currently defines that method as an OperationContract?

[OperationContract]
public Void SaveUser(Users U);

You can just add another method that takes a List, or an Array:

// added to the service interface
[OperationContract]
public Void SaveUsers(List<Users> users);

// added to the implementation of the service
public Void SaveUsers(List<Users> users) {
  foreach(var user in users)
  {
    SaveUser(user);
  }
}

This is of course assuming you have control over the WCF service and can add that to its contract.

Upvotes: 1

Ken D
Ken D

Reputation: 5968

You mean to send through WCF and not "to WCF", you can serialize any object to be sent in networking applications and de-serialize it on the other end to regroup its contents into the original object. This way you don't need to loop, send the whole list (serialized) and on the other end you do the specific operation on each item alone.

Upvotes: 0

Related Questions