Consultor Eletrônico



Kbase P154712: What is the recommended way to return a .NET DataSet to an OpenEdge Web Service ?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   21/10/2009
Status: Unverified

GOAL:

What is the recommended way to return a .NET DataSet to an OpenEdge Web Service ?

GOAL:

How to send a .NET DataSet to an OpenEdge Web Service ?

FACT(s) (Environment):

OpenEdge 10.1C
OpenEdge 10.2x
All Supported Operating Systems

FIX:

The recommended way to send a .NET DataSet to an OpenEdge Web Service is through a LONGCHAR input parameter. The reason for this is that a .NET DataSet does not map directly to a ProDataSet input parameter, so it's best to serialize the .NET DataSet and send this to the OpenEdge Web Service in order to use the READ-XML() method to read the data into a ProDataSet. This is better explained through an example.
Assume you have the following ABL procedure running on the AppServer which you are exposing as an OpenEdge Web Service:

DEFINE INPUT PARAMETER lcdsInput AS LONGCHAR NO-UNDO.
DEFINE VARIABLE hdsInput AS HANDLE NO-UNDO.

CREATE DATASET hdsInput.
hdsInput:NAME = "dsOutput".
hdsInput:NAMESPACE-URI = "dsOutput".

hdsInput:READ-XML("LONGCHAR",
lcdsInput,
"EMPTY",
?,
?,
?,
?).

hdsInput:WRITE-XML("FILE",
"E:\Temp2\dotNet\WebServices\Server\lcdsInput.xml",
TRUE,
?,
?,
TRUE,
FALSE,
TRUE).

DELETE OBJECT hdsInput.

From a C# .NET client you would then run the following code to send a .NET DataSet to the OpenEdge Web Service:
private void button2_Click(object sender, EventArgs e)
{
// Create a new .NET DataSet that includes the changes.
DSChanges = myDS.GetChanges(DataRowState.Modified);

// The OpenEdge Web Service expects a content with the UTF-8 encoding. Since a .NET string is
// UTF-16 by default, overload the StringWriter class to create a UTF-8 string instead.
StringWriterWithEncoding sw = new StringWriterWithEncoding(Encoding.UTF8);

// Serialize the modified .NET DataSet as a diffgram including it's schema.
// "DSChanges.WriteXml(sw, XmlWriteMode.DiffGram)" does not include the schema, thus causing
// the OpenEdge READ-XML to return an empty ProDataSet.
&.nbsp; XmlSerializer ser = new XmlSerializer(typeof(DataSet));
ser.Serialize(sw, DSChanges);
string strDiffgramInlineSchema = sw.ToString();
sw.Close();

//Call the Web Service operation and provide the serialized .NET DataSet as an input parameter
WSTest.WSTestService ws = new WSTest.WSTestService();
ws.lcDSTestIn(strDiffgramInlineSchema);
}

//Overload the StringWriter class to create UTF-8 strings
public class StringWriterWithEncoding : StringWriter
{
Encoding encoding;
public StringWriterWithEncoding(Encoding encoding)
{
this.encoding = encoding;
}
public override Encoding Encoding
{
get { return encoding; }
}
}.