服务引用生成不正确的方法签名

Service Reference Generates Incorrect Method Signature

我们有一个 asmx 网络服务项目。当我使用 Add Service Reference 选项将它添加到项目时,一切正常。然而,当我的同事这样做时,他得到了操作合约中定义的方法的错误签名。

错误的签名我的意思是原始方法接收实体作为参数,这些实体是在我同事的项目中作为 DataSet 参数生成的(服务引用结构也不同,如图所示。我的同事有更多的东西) .我们正在使用 VS 2013。

怎么回事?

编辑:

服务合同

  [ServiceContract]
    public interface INetTransTntIntegration
    {
        [OperationContract]
        string CreateGlbTrns1LineCard(GlbTrns1LineCardEntity ent);

        [OperationContract]
        void CreateGlbTrns1LineCardTest();
    }

生成的代码(同事的错误代码)

namespace TNT.ServiceReference {
using System.Data;


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference.INetTransTntIntegration")]
public interface INetTransTntIntegration {

    // CODEGEN: Parameter 'CreateGlbTrns1LineCardResult' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCard", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
    TNT.ServiceReference.CreateGlbTrns1LineCardResponse CreateGlbTrns1LineCard(TNT.ServiceReference.CreateGlbTrns1LineCardRequest request);

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCard", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardResponse")]
    System.Threading.Tasks.Task<TNT.ServiceReference.CreateGlbTrns1LineCardResponse> CreateGlbTrns1LineCardAsync(TNT.ServiceReference.CreateGlbTrns1LineCardRequest request);

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTest", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTestResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
    void CreateGlbTrns1LineCardTest();

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTest", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTestResponse")]
    System.Threading.Tasks.Task CreateGlbTrns1LineCardTestAsync();
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="CreateGlbTrns1LineCard", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class CreateGlbTrns1LineCardRequest {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Data.DataSet ent;

    public CreateGlbTrns1LineCardRequest() {
    }

    public CreateGlbTrns1LineCardRequest(System.Data.DataSet ent) {
        this.ent = ent;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="CreateGlbTrns1LineCardResponse", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class CreateGlbTrns1LineCardResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public string CreateGlbTrns1LineCardResult;

    public CreateGlbTrns1LineCardResponse() {
    }

    public CreateGlbTrns1LineCardResponse(string CreateGlbTrns1LineCardResult) {
        this.CreateGlbTrns1LineCardResult = CreateGlbTrns1LineCardResult;
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface INetTransTntIntegrationChannel : TNT.ServiceReference.INetTransTntIntegration, System.ServiceModel.IClientChannel {
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class NetTransTntIntegrationClient : System.ServiceModel.ClientBase<TNT.ServiceReference.INetTransTntIntegration>, TNT.ServiceReference.INetTransTntIntegration {

    public NetTransTntIntegrationClient() {
    }

    public NetTransTntIntegrationClient(string endpointConfigurationName) : 
            base(endpointConfigurationName) {
    }

    public NetTransTntIntegrationClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) {
    }

    public NetTransTntIntegrationClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) {
    }

    public NetTransTntIntegrationClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress) {
    }

    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    TNT.ServiceReference.CreateGlbTrns1LineCardResponse TNT.ServiceReference.INetTransTntIntegration.CreateGlbTrns1LineCard(TNT.ServiceReference.CreateGlbTrns1LineCardRequest request) {
        return base.Channel.CreateGlbTrns1LineCard(request);
    }

    public string CreateGlbTrns1LineCard(System.Data.DataSet ent) {
        TNT.ServiceReference.CreateGlbTrns1LineCardRequest inValue = new TNT.ServiceReference.CreateGlbTrns1LineCardRequest();
        inValue.ent = ent;
        TNT.ServiceReference.CreateGlbTrns1LineCardResponse retVal = ((TNT.ServiceReference.INetTransTntIntegration)(this)).CreateGlbTrns1LineCard(inValue);
        return retVal.CreateGlbTrns1LineCardResult;
    }

    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    System.Threading.Tasks.Task<TNT.ServiceReference.CreateGlbTrns1LineCardResponse> TNT.ServiceReference.INetTransTntIntegration.CreateGlbTrns1LineCardAsync(TNT.ServiceReference.CreateGlbTrns1LineCardRequest request) {
        return base.Channel.CreateGlbTrns1LineCardAsync(request);
    }

    public System.Threading.Tasks.Task<TNT.ServiceReference.CreateGlbTrns1LineCardResponse> CreateGlbTrns1LineCardAsync(System.Data.DataSet ent) {
        TNT.ServiceReference.CreateGlbTrns1LineCardRequest inValue = new TNT.ServiceReference.CreateGlbTrns1LineCardRequest();
        inValue.ent = ent;
        return ((TNT.ServiceReference.INetTransTntIntegration)(this)).CreateGlbTrns1LineCardAsync(inValue);
    }

    public void CreateGlbTrns1LineCardTest() {
        base.Channel.CreateGlbTrns1LineCardTest();
    }

    public System.Threading.Tasks.Task CreateGlbTrns1LineCardTestAsync() {
        return base.Channel.CreateGlbTrns1LineCardTestAsync();
    }
}

我正确生成的代码

namespace TNT.NettransSvc {


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="NettransSvc.INetTransTntIntegration")]
    public interface INetTransTntIntegration {

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCard", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardResponse")]
        string CreateGlbTrns1LineCard(LLMTESTADAPTER.EntityClasses.GlbTrns1LineCardEntity ent);

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCard", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardResponse")]
        System.Threading.Tasks.Task<string> CreateGlbTrns1LineCardAsync(LLMTESTADAPTER.EntityClasses.GlbTrns1LineCardEntity ent);

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTest", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTestResponse")]
        void CreateGlbTrns1LineCardTest();

        [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTest", ReplyAction="http://tempuri.org/INetTransTntIntegration/CreateGlbTrns1LineCardTestResponse")]
        System.Threading.Tasks.Task CreateGlbTrns1LineCardTestAsync();
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface INetTransTntIntegrationChannel : TNT.NettransSvc.INetTransTntIntegration, System.ServiceModel.IClientChannel {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class NetTransTntIntegrationClient : System.ServiceModel.ClientBase<TNT.NettransSvc.INetTransTntIntegration>, TNT.NettransSvc.INetTransTntIntegration {

        public NetTransTntIntegrationClient() {
        }

        public NetTransTntIntegrationClient(string endpointConfigurationName) : 
                base(endpointConfigurationName) {
        }

        public NetTransTntIntegrationClient(string endpointConfigurationName, string remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }

        public NetTransTntIntegrationClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(endpointConfigurationName, remoteAddress) {
        }

        public NetTransTntIntegrationClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }

        public string CreateGlbTrns1LineCard(LLMTESTADAPTER.EntityClasses.GlbTrns1LineCardEntity ent) {
            return base.Channel.CreateGlbTrns1LineCard(ent);
        }

        public System.Threading.Tasks.Task<string> CreateGlbTrns1LineCardAsync(LLMTESTADAPTER.EntityClasses.GlbTrns1LineCardEntity ent) {
            return base.Channel.CreateGlbTrns1LineCardAsync(ent);
        }

        public void CreateGlbTrns1LineCardTest() {
            base.Channel.CreateGlbTrns1LineCardTest();
        }

        public System.Threading.Tasks.Task CreateGlbTrns1LineCardTestAsync() {
            return base.Channel.CreateGlbTrns1LineCardTestAsync();
        }
    }
}

我同事的 visual studio 出于某种原因没有自动转换实体,所以我不得不为那些 dll(包含实体 definitions/operations)显式设置重用选项,以便识别实体.

在我的情况下,我不需要检查任何这些,但它工作正常。

感谢@HenkHolterman 抽出时间。