在WCF服务调用中传输my-model-type [英] Transporting my-model-type in WCF service call

查看:103
本文介绍了在WCF服务调用中传输my-model-type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



认为这很简单-至少很容易问:我在IIS-7托管的网站上公开了有效的WCF服务,并使用了消耗Silverlight 4的应用程序对其进行了调用.然后我有一个服务方法,如:

Hi,

Think this one is simple - at least simple to ask: I have a working WCF service exposed on a IIS-7 hosted website and a Silverlight 4 consuming app to call it. Then I have a service method like:

public ObservableCollection<Headline> GetHeadlines()
{...}



其中



Where

Heading

是WS和SL应用程序都引用的模型项目的一部分.

现在,当我发布此WS并在IE中浏览它时,它失败并显示:

is part of a model-project referenced by both the WS and the SL app.

Now, when I publish this WS and browse it in IE it fails with:

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.



但是,如果我将方法签名更改为:



However if I change the method signature to:

public ObservableCollection<string> GetHeadlines()
{...}



一切都很好.

似乎适用于所有内置类型,例如string和List< string>等等,但不适用于我的模型课.我不明白为什么.也许是一些流媒体问题?

模型类非常简单-没有基于接口的模型-仅有两个成员的占位符.



it all works fine.

Seems to work for all build-in types like string and List<string> etc. but not for my model classes. I don''t understand why. Is it some streaming issue perhaps?

Model class is really simple - no base, on interface - just a placeholder with two members.

推荐答案

您需要使用DataContract和DataMember将其序列化为WCF属性. MSDN数据合同简介 [
You need to make it serializable for WCF, with the DataContract and DataMember attributes. MSDN introduction to data contracts[^] may help you.


这篇关于在WCF服务调用中传输my-model-type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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