将数组列表传递给 WCF 应用程序 [英] Pass the array list to the WCF application

查看:31
本文介绍了将数组列表传递给 WCF 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WCF 的新手.我有一个场景,我有 .

I am new to WCF. I have a scenario where i have .

当我试图传递数组列表时,它给出了错误.请看图.

When i am trying to pass the array list it giving the error. Please, have the look to image.

ICommissionService 定义

[GeneratedCode("System.ServiceModel", "4.0.0.0")]
[ServiceContract(ConfigurationName = "FPCommission.ICommissionService")]
public interface ICommissionService
{
   [OperationContract(Action = "http://tempuri.org/ICommissionService/GetCommisionResponse",
                      ReplyAction = "http://tempuri.org/ICommissionService/GetCommisionResponseResponse")]
   object[] GetCommisionResponse(object[] loc_);
}

我仍然没有得到解决方案.

I am still not get the solution.

推荐答案

这一行是问题,来自服务:

This line is the problem, from the service:

object[] GetCommisionResponse(object[] loc_);

您在这里告诉 WCF 的是您将返回一个 Object 数组.正因为如此,客户端希望取回一个 Object 数组.这当然不是你实际给予的.

What you've told WCF here is that you're going to be returning an array of Object. Because of that, the client expects to get back an array of Object. That of course is not what you're actually giving it.

子类在 WCF 中的工作方式与它们在其他地方的工作方式不同.您必须在服务中明确定义您要返回的内容,因为客户端必须知道期望什么并为其创建类.

Subclasses don't work the same way in WCF that they work elsewhere. You have to explicitly define in the service what you're returning, because the client has to know what to expect and create classes for.

因此,如果您实际上返回的是 Flight 数组,请将其更改为:

So if you're actually returning an array of Flight, change it to this:

Flight[] GetCommisionResponse(object[] loc_);

但如果您要返回某些内容及其自身的某些子类,则必须使用 KnownType 属性.

But if you're returning something and some subclasses of itself, you'll have to use the KnownType attribute.

[KnownType(typeof(FlightSubClass))]
Flight[] GetCommisionResponse(object[] loc_);

您可以使用 ServiceKnownType<在界面上做同样的事情/a>,而且只需要做一次.

You can do the same thing on the Interface using ServiceKnownType, and only have to do it once.

这篇关于将数组列表传递给 WCF 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆