web服务响应使用MessageContract时变成ref参数 [英] Webservice Response is turned into ref parameter when using MessageContract
问题描述
我已经定义了以下接口
[ServiceContract]
public interface IHealthProducts
{
[OperationContract()]
ResponseClass OrderSelfSignedHealthCertificate();
}
它返回以下类型
Which returns the following type
[MessageContract]
public class ResponseClass
{
[MessageBodyMember]
public string AnimalSpeciesCode
{
get;
set;
}
[MessageBodyMember]
public int VBN
{
get;
set;
}
}
我期望生成的客户端code会暴露在以下方式OrderSelfSignedHealthCertificate方法:
I expected that the generated client code would expose the OrderSelfSignedHealthCertificate method in the following way:
HealthProductsClient client = new HealthProductsClient();
ResponseClass response = client.OrderSelfSignedHealthCertificate();
相反,属性的 ResponseClass 的未包裹在ResponseClass,但像这样暴露:
Instead, the properties of ResponseClass aren't wrapped in the ResponseClass, but exposed like so:
string OrderSelfSignedHealthCertificate(out int VBN)
当我交换MessageContract一个DataContract属性和MessageBodyMember的数据成员属性,我得到预期的行为(ResponseClass响应类型)。 我需要的MessageContract但是,因为我需要把一些属性在SOAP头。
When I exchange the MessageContract for a DataContract attribute and the MessageBodyMember for a DataMember attribute, I get the expected behaviour (ResponseClass response type). I need the MessageContract however, because I need to put some of the properties in the SOAP header.
我是不是做错了什么?这是正常的行为呢?我如何获得的 ResponseClass 的返回类型,使用MessageContract什么时候?
Am I doing something wrong? Is this normal behaviour? How do I get a ResponseClass return type, when using a MessageContract?
任何帮助非常AP preciated。
Any help greatly appreciated.
推荐答案
在你的 [MessageContract]
包含多个 [MessageBodyMember]
,则WCF将返回第一个从(你的情况 AnimalSpecies code
)的服务调用的返回值,以及所有其他被返回退出
或 REF
paraemters。
When your [MessageContract]
contains more than one [MessageBodyMember]
, then WCF will return the first one as return value from the service call (AnimalSpeciesCode
in your case), and all others are returned as out
or ref
paraemters.
您可以通过让解决这个问题只有一个 [MessageBodyMember]
封装了你需要有回报,这样的事情的所有项目的消息的合同:
You can solve this by having only a single [MessageBodyMember]
in your message contract that encapsulates all items you need to have return, something like this:
[DataContract]
class CompoundData
{
public string AnimalSpeciesCode { get; set; }
public int VBN { get; set; }
}
[MessageContract]
public class ResponseClass
{
[MessageBodyMember]
public CompoundData Payload { get; set; }
}
在这种情况下, CompoundData code>应该是从你的服务调用的返回值 - 包含你需要两个元素
In this case, the CompoundData
should be the return value from your service call - containing both elements you need.
这篇关于web服务响应使用MessageContract时变成ref参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!