我的客户端正在使用从WSDL创建的代理...是否可以设置服务发送列表而不是MyCustomObject[]
?WCF服务返回数组而不是列表
我使用
svcutil /t:metadata /ct:System.Collections.Generic.List`1 localhost:8080/managedApp
但不工作...
我的客户是在Visual C++
IDE是的Visual Studio 2012 - >不能添加服务引用
我的客户端正在使用从WSDL创建的代理...是否可以设置服务发送列表而不是MyCustomObject[]
?WCF服务返回数组而不是列表
我使用
svcutil /t:metadata /ct:System.Collections.Generic.List`1 localhost:8080/managedApp
但不工作...
我的客户是在Visual C++
IDE是的Visual Studio 2012 - >不能添加服务引用
好吧......在我放弃了年底,我刚发来的数据作为数组,而不是性病:列表...
我这是怎么做的: 1.-得到的元数据服务使用svcutil/t:元数据(注意:服务必须运行)。 2.-创建代理wsutil * .wsdl * .xsd 3.-将代理文件(.h和.c)添加到我的客户端,并将代理功能用于服务。
阵列,如果你不熟悉C语言编程,虽然有点棘手...
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; }
}
}
和调用数组我的客户端:
// *** 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);
希望这可以帮助...
是的。
/collectionType:如果您直接使用svcutil.exe,或者如果“添加服务引用” 转到高级 - >集合类型并更改为任何你想要的。
为什么它很可能是使用Web服务/ WCF“服务”时,您的端点总是 接收XML/JSON序列化的数据,比这个数据进行反序列化到你的C++数据类型, ,它取决于你在哪个集合键入您想要反序列化包含某些集合的收到数据。
嗨Nightwish91,我认为从Visual C++“添加服务引用”已禁用Visual Studio 2012,我也试过svcutil,因为你可以在我的文章中看到,但仍然收到wchar_t **(它的行为像一个数组)...知道我错过了什么吗? – masuberu
你说它“不起作用”;它怎么不工作? – carlosfigueira
您需要记住,服务不会发送列表或数组。他们发送XML。列表或数组或其他东西在客户端,而不是服务器。 –
嗨约翰,是的,你是正确的客户端在他们的数据类型转换为XML,JSON等......但为什么WCF客户端在C#可以发送集合甚至自定义集合和服务器接他们?我的客户端是Visual C++,所以我徘徊,如果我可以有相同的行为... – masuberu