WCF服务返回数组而不是列表 [英] WCF service returning array instead of List
问题描述
我的客户端正在使用从WSDL创建的代理...是否可以将服务设置为发送列表而不是MyCustomObject[]
?
My client is using proxy created from WSDL... Is it possible to setup the service to send List instead of MyCustomObject[]
?
我正在使用
svcutil /t:metadata /ct:System.Collections.Generic.List`1 localhost:8080/managedApp
但不起作用...
我的客户端使用Visual C ++
My client are in Visual C++
IDE是Visual Studio 2012->无法添加服务引用
IDE is Visual Studio 2012 --> cannot add service reference
推荐答案
确定...最后,我只是将数据作为数组发送,而不是std:list ...
Ok... at the end I gave up, I just sent the data as array instead of std:list...
这是我的方法: 1.-使用svcutil/t:metadata从服务中获取元数据(注意:服务必须正在运行). 2.-创建代理wsutil * .wsdl * .xsd 3.-将代理文件(.h和.c)添加到我的客户端,并使用代理功能访问服务.
this is how I did it: 1.- get the metadata from the service using svcutil /t:metadata (NOTE: service has to be running). 2.- create the proxy wsutil *.wsdl *.xsd 3.- add proxy files (.h and .c) to my client and use the proxy functions to the service.
如果您不熟悉c编程,则数组会有些棘手...
Array are a little bit tricky if you are not familiar with c programming though...
DataContract:
DataContract:
[DataContract]
public class CompositeType
{
CompositeType2[] ctListValue;
bool boolValue;
string stringValue;
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
[DataMember]
public CompositeType2[] CtListValue
{
get { return ctListValue; }
set { ctListValue = value; }
}
}
[DataContract]
public class CompositeType2
{
bool boolValue;
string stringValue;
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
和我的客户端调用数组:
and my client side for the calls to array:
// *** COMPOSITETYPE CALL
CompositeType * co = new CompositeType();
co->BoolValue = true;
co->StringValue = L"Im co";
CompositeType2 co0;
co0.BoolValue = true;
co0.StringValue = L"Im co0";
CompositeType2 co1;
co1.BoolValue = true;
co1.StringValue = L"Im co1";
CompositeType2 co2;
co2.BoolValue = true;
co2.StringValue = L"Im co2";
CompositeType2 ** comType2; // <-- this is my CompositeType2[] I will send to the service
comType2 = new CompositeType2*[3];
comType2[0] = &co0;
comType2[1] = &co1;
comType2[2] = &co2;
co->CtListValue = comType2;
co->CtListValueCount = 3;
CompositeType* result2;
BasicHttpBinding_IHelloWorldService_SayHelloCompType(
proxy, co, &result2,
heap, NULL, 0, NULL, error);
希望这对您有帮助...
Hope this helps...
这篇关于WCF服务返回数组而不是列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!