Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to pass a table of data
Message
De
08/12/2004 13:28:49
 
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Divers
Thread ID:
00967555
Message ID:
00967821
Vues:
7
Stephen,

Here's a brief example of getting a DataSet through a WebService.
if (this.MyData == null)
    this.MyData = new MyDataSet();
XML = this.oWS.GetMyData(this.MyKey);
this.MyData.FillWithXml(XML);
The .FillWithXML() method is a method we have on all our Typed DataSets. It simply does this:
StringReader sr = new StringReader(XML);
this.ReadXml(sr, XmlReadMode.InferSchema);
this.AcceptChanges();
Your WebService method does whatever it needs to do to get the data and simply returns MyDataSet.GetXml().

OK, so now you probably want to know how to update. There's probably a coupla different ways to do it, but I do it by sending two XML strings back through the Web Service method ... ChangeXML and DeleteXML.
DataSet dsChanged = this.MyData.GetChanges();
DataSet dsDeleted = this.MyData.GetChanges(DataRowState.Deleted);
			
ChangeXML = dsChanged.GetXml();
if (dsDeleted != null)
{
	// -- The dsDeleted DataSet contains only the deleted rows
	//    However, since the GetXML() method ignores the Deleted
	//    rows we need to un-delete them first.
	//
	dsDeleted.RejectChanges();
	DeleteXML = dsDeleted.GetXml();
}
else
	DeleteXML = "";

// This is a simplistic view. There would be more stuff you might need
// to do as far as matching keys and stuff like that.
if (this.oWS.SaveMyData(ChangeXML, DeleteXML))
    this.MyData.AcceptChanges();
The WebService SaveMyData() method would be something like this:
[WebMethod(Description="Saves info for one MyData entity")]
public bool SaveMyData(string ChangeXML, string DeleteXML)
{
	MyDataSet dsChanged = new MyDataSet();
	MyDataSet dsDeleted = new MyDataSet();

	try
	{
		dsChanged.FillWithXml(ChangeXML);
		if (DeleteXML != "")
			dsDeleted.FillWithXml(DeleteXML);
	}
	catch (Exception ex)
	{
		return false;
	}

	bool IsOK = true;

	// do all your processing for saving 
	// (call your Biz class or DataAccess class)


	return IsOK;
}
Does this help?

~~Bonnie



>>Don't return .NET objects (like DataSets) from a webmethod. Instead, return XML. There is a difference in the way they are

serialized (Diffgram vs. XML string). Besides, what if the client is not .NET? Would it know what to do with a diffgram? Newer

version of foxpro know how to handle it but many platforms don't.
>>
>>Returning Datasets or custom .NET objects is fine for remoting if you are sure the client is .NET.
>
>Ok so for us dummies, I have the ds, and I make an XML file to pass or do I make a string of xml?
>
>And how does my WS catch in on the receiving end? This is a registration component, where your install fires off who you are

and what types of business with our products you are dealing with back to us.
>
>Thanks.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform