通用的返回类型和客户方的命名问题

通用的返回类型和客户方的命名问题

本文介绍了与MessageContract,通用的返回类型和客户方的命名问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建,它使用MessageContracts,因为我想自定义字段添加到我的SOAP头的Web服务。在一$p$pvious话题,我了解到,复合反应已被包装。为了这个目的,我设计一个通用ResponseWrapper此类类。

I'm building a web service which uses MessageContracts, because I want to add custom fields to my SOAP header. In a previous topic, I learned that a composite response has to be wrapped. For this purpose, I devised a generic ResponseWrapper class.

[MessageContract(WrapperNamespace = "http://mynamespace.com",
                    WrapperName="WrapperOf{0}")]
public class ResponseWrapper<T>
{
    [MessageBodyMember(Namespace = "http://mynamespace.com")]
    public T Response
    {
        get;
        set;
    }
}

我做了一个ServiceResult基类,定义如下:

I made a ServiceResult base class, defined as follows:

[MessageContract(WrapperNamespace = "http://mynamespace.com")]
public class ServiceResult
{
    [MessageBodyMember]
    public bool Status
    {
        get;
        set;
    }

    [MessageBodyMember]
    public string Message
    {
        get;
        set;
    }

    [MessageBodyMember]
    public string Description
    {
        get;
        set;
    }
}

要能够在响应,我用一个派生类ServiceResult的,它使用泛型请求上下文:

To be able to include the request context in the response, I use a derived class of ServiceResult, which uses generics:

[MessageContract(WrapperNamespace = "http://mynamespace.com",
                WrapperName = "ServiceResultOf{0}")]
public class ServiceResult<TRequest> : ServiceResult
{
    [MessageBodyMember]
    public TRequest Request
    {
        get;
        set;
    }
}

这是用在通过以下方式

[OperationContract()]
ResponseWrapper<ServiceResult<HCCertificateRequest>> OrderHealthCertificate(RequestContext<HCCertificateRequest> context);

我预计将产生我的客户code为

I expected my client code to be generated as

ServiceResultOfHCCertificateRequest OrderHealthCertificate(RequestContextOfHCCertificateRequest context);

相反,我得到如下:

Instead, I get the following:

ServiceResultOfHCCertificateRequestzSOTD_SSj OrderHealthCertificate(CompType1 c1, CompType2 c2, HCCertificateRequest context);

CompType1 CompType2 是属性的的RequestContext 类。的问题是,散列加到 ServiceResultOfHCCertificateRequestzSOTD_SSj 的末端。怎么办,我需要定义我一般返回类型为要生成的客户端类型预期(没有#)?

CompType1 and CompType2 are properties of the RequestContext class. The problem is that a hash is added to the end of ServiceResultOfHCCertificateRequestzSOTD_SSj. How do I need define my generic return types in order for the client type to be generated as expected (without the hash)?

推荐答案

我们也有过问题,返回一个通用的清单在WCF。

We have also had problems returning a generic list over WCF.

这适用于我们的解决方案是创建一个具有单个属性的一类,而该属性是一个通用的清单。

The solution that works for us is to create a class that has a single property, and that property is a generic list.

然后我们发送该类了WCF。如果你有很多这样的列表,你可以创建一个具有T类型列表的类,这样,当你创建类,你可以指定你想要的类型列表中。

Then we send that class over WCF. If you have many such lists you can create a class that has a list of type T. So that when you create the class you can specify which type of list you want.

这篇关于与MessageContract,通用的返回类型和客户方的命名问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:42