消息或具有 MessageContractAttribute 和其他不同类型参数的类型 [英] Message or a type that has MessageContractAttribute and other parameters of different types

查看:34
本文介绍了消息或具有 MessageContractAttribute 和其他不同类型参数的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 WCF 服务,其中一些类具有 [MessageContract] 属性,而有些则没有.

I'm developing WCF services where some classes have the [MessageContract] attribute, and some don't.

当我尝试运行服务时,我收到以下错误消息:

When I try to run the services I get this error message below:

无法加载操作ProcessOperation",因为它具有 System.ServiceModel.Channels.Message 类型的参数或返回类型,或者具有 MessageContractAttribute 和其他不同类型参数的类型.使用 System.ServiceModel.Channels.Message 或带有 MessageContractAttribute 的类型时,该方法不得使用任何其他类型的参数.

The operation 'ProcessOperation' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters.

这是否意味着所有服务都必须有 [MessageContract] 尽管它们没有关联?

Does it mean that all the services must have [MessageContract] although they are not related?

推荐答案

不,这意味着您在方法上有多个参数,其中一些不是消息.尝试将接口发布到您的服务.

No, it means that you have multiple parameters on the method and some of them are not messages. Try posting the interface to your service.

这篇博文 解释:

... 问题是消息契约不能与其他参数类型同时使用.在这种情况下,操作的返回值是一个字符串.返回值只是另一个输出参数,因此此操作将消息合同消息与原始参数类型混合.这会失败,因为消息契约让您可以控制 SOAP 消息的布局,从而防止系统融入这些附加参数.

... problem is that message contracts cannot be used at the same time as other parameter types. In this case, the return value of the operation is a string. Return values are just another output parameter, so this operation is mixing a message contract message with a primitive parameter type. This fails because message contracts give you control of the layout of the SOAP message, preventing the system from melding in these additional parameters.

重要提示:

顺便说一下,当您尝试混合消息契约时,您得到的错误消息如下所示.

By the way, the error message you get when you try to mix message contracts looks like this.

这篇关于消息或具有 MessageContractAttribute 和其他不同类型参数的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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