简体   繁体   English

与无.Net客户端共享WCF服务中的.Net类型

[英]Sharing .Net types in a wcf service with a no .Net client

I develop a webservice in WCF returning a dataset . 我在WCF中开发了一个返回datasetwebservice

When I create my .Net test app to consume the WCF I can receive the dataset and assign it to a datagrid without any problem. 当我创建.Net测试应用程序以使用WCF时,我可以接收dataset并将其分配给datagrid而不会出现任何问题。 Visual Studio does all the job for me. Visual Studio为我完成了所有工作。

But when my partner is trying to consume the WCF in c++ he told me he processes the data as a XML and does the parsing as a string. 但是,当我的伙伴尝试使用c ++消费WCF时,他告诉我他将数据作为XML处理,并作为字符串进行解析。

I guess there should exist a better way he consumes my data. 我想应该有一种更好的方式来使用我的数据。
But because I'm not familiar with c++, don't know how should that work. 但是因为我不熟悉c ++,所以不知道该如何工作。
Should I create a class for my Dataset row and return a MyClass array instead? 是否应该为Dataset行创建一个类并返回MyClass数组?

Now, on the other hand if I want receive a Dataset from him? 现在,另一方面,是否要从他那里接收数据集?
How will he create the XML? 他将如何创建XML?
Or should I receive a XML string instead and do the parsing on my side? 还是应该改为接收XML字符串并在我这一边进行解析?

EDIT: Just in case c++ is under Linux. 编辑:以防万一c ++在Linux下。

The DataSet is a .Net data type that won't have a specific analogue in non .Net languages. DataSet是.Net数据类型,在非.Net语言中没有特定的类似物。 If the C++ consumer is using .Net, then in theory the DataSet should be deserializable. 如果C ++使用者正在使用.Net,则理论上应该可以反序列化DataSet。

For an API, you generally want to use simple custom objects and collection types that can be serialized as an array. 对于API,通常希望使用可以序列化为数组的简单自定义对象和集合类型。 For example, if your DataSet has a schema that contains 例如,如果您的数据集的架构包含

Column1    int
Column2    string
Column3    bool

and do forth, then you could create a custom class to represent that: 然后,您可以创建一个自定义类来表示该类:

public class YourObjectType 
{
    public int Column1 { get; set; }
    public string Column2 { get; set; }
    public bool Column3 { get; set; }
}

And store your DataSet contents in an appropriate collection object. 并将您的DataSet内容存储在适当的集合对象中。 If sorting is important, then convert to a Queue<YourObjectType> , otherwise List<YourObjectType> is generally the best approach. 如果排序很重要,则转换为Queue<YourObjectType> ,否则List<YourObjectType>通常是最佳方法。 Both of these types serialize to an array. 这两种类型都序列化为数组。 You can iterate across the rows in the dataset to create one object per row and then place that object in the new collection. 您可以遍历数据集中的行以在每一行中创建一个对象,然后将该对象放置在新集合中。

As a further tip: for a performance boost, look into getting rid of the DataSet altogether. 另一个提示:为了提高性能,请考虑完全摆脱DataSet。 If you are pulling from a database, it will be better to get a DataReader instead of a DataSet, and then map the contents of that DataReader directly into the new object type and collection. 如果要从数据库中提取数据,则最好使用DataReader而不是DataSet,然后将该DataReader的内容直接映射到新的对象类型和集合中。 DataSets are computationally expensive compared to directly reading database data. 与直接读取数据库数据相比,数据集在计算上昂贵。

Consider exposing a REST endpoint (via WCF or WebAPI) instead of a Web Services/SOAP endpoint. 考虑公开REST端点(通过WCF或WebAPI)而不是公开Web Services / SOAP端点。 Then your C++ developer can use the C++ REST SDK to build his client. 然后,您的C ++开发人员可以使用C ++ REST SDK来构建其客户端。

http://msdn.microsoft.com/en-us/magazine/dn342869.aspx http://msdn.microsoft.com/en-us/magazine/dn342869.aspx

More info: http://channel9.msdn.com/Events/GoingNative/2013/A-Cpp-REST-SDK-OSS-web-services-on-Windows-and-Linux 更多信息: http : //channel9.msdn.com/Events/GoingNative/2013/A-Cpp-REST-SDK-OSS-web-services-on-Windows-and-Linux

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM