添加的服务引用的自动生成代码中的循环基类依赖错误

Posted

技术标签:

【中文标题】添加的服务引用的自动生成代码中的循环基类依赖错误【英文标题】:Circular base class dependency error in autogenerated code of the added service reference 【发布时间】:2020-07-31 08:18:59 【问题描述】:

我创建了一个我想要使用的 WCF Web 服务。在我的客户端上,我添加了一个新的服务参考。它找到它,我给它一个命名空间,然后单击“确定”。它会生成适当的代码,但是当我重新构建应用程序时,出现错误:

Circular base class dependency involving 'WSHelperClient' and 'WSHelperClient'

这是自动生成的代码。如果我替换“WSHelperClient.WSHelper”。使用“”,它修复了循环基类依赖错误。

有人知道为什么自动生成的代码没有编译,我需要手动更改它吗?

namespace WSHelperClient.WSHelper 
using System.Runtime.Serialization;
using System;


[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="PowerShellResponse", Namespace="http://schemas.datacontract.org/2004/07/WSHelper")]
[System.SerializableAttribute()]
public partial class PowerShellResponse : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged 

    [System.NonSerializedAttribute()]
    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private string DescriptionField;

    [System.Runtime.Serialization.OptionalFieldAttribute()]
    private bool HadErrorsField;

    [global::System.ComponentModel.BrowsableAttribute(false)]
    public System.Runtime.Serialization.ExtensionDataObject ExtensionData 
        get 
            return this.extensionDataField;
        
        set 
            this.extensionDataField = value;
        
    

    [System.Runtime.Serialization.DataMemberAttribute()]
    public string Description 
        get 
            return this.DescriptionField;
        
        set 
            if ((object.ReferenceEquals(this.DescriptionField, value) != true)) 
                this.DescriptionField = value;
                this.RaisePropertyChanged("Description");
            
        
    

    [System.Runtime.Serialization.DataMemberAttribute()]
    public bool HadErrors 
        get 
            return this.HadErrorsField;
        
        set 
            if ((this.HadErrorsField.Equals(value) != true)) 
                this.HadErrorsField = value;
                this.RaisePropertyChanged("HadErrors");
            
        
    

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName) 
        System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if ((propertyChanged != null)) 
            propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        
    


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="WSHelper.IWSHelper")]
public interface IWSHelper 

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWSHelper/ConvertUserMailboxToShared", ReplyAction="http://tempuri.org/IWSHelper/ConvertUserMailboxToSharedResponse")]
    WSHelperClient.WSHelper.PowerShellResponse ConvertUserMailboxToShared(string email);

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWSHelper/ConvertUserMailboxToShared", ReplyAction="http://tempuri.org/IWSHelper/ConvertUserMailboxToSharedResponse")]
    System.Threading.Tasks.Task<WSHelperClient.WSHelper.PowerShellResponse> ConvertUserMailboxToSharedAsync(string email);

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWSHelper/RemoveUserLicences", ReplyAction="http://tempuri.org/IWSHelper/RemoveUserLicencesResponse")]
    WSHelperClient.WSHelper.PowerShellResponse RemoveUserLicences(string upn);

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWSHelper/RemoveUserLicences", ReplyAction="http://tempuri.org/IWSHelper/RemoveUserLicencesResponse")]
    System.Threading.Tasks.Task<WSHelperClient.WSHelper.PowerShellResponse> RemoveUserLicencesAsync(string upn);

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWSHelper/RemoveMailboxFromAddressBook", ReplyAction="http://tempuri.org/IWSHelper/RemoveMailboxFromAddressBookResponse")]
    WSHelperClient.WSHelper.PowerShellResponse RemoveMailboxFromAddressBook(string email);

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IWSHelper/RemoveMailboxFromAddressBook", ReplyAction="http://tempuri.org/IWSHelper/RemoveMailboxFromAddressBookResponse")]
    System.Threading.Tasks.Task<WSHelperClient.WSHelper.PowerShellResponse> RemoveMailboxFromAddressBookAsync(string email);


[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IWSHelperChannel : WSHelperClient.WSHelper.IWSHelper, System.ServiceModel.IClientChannel 


[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class WSHelperClient : System.ServiceModel.ClientBase<WSHelperClient.WSHelper.IWSHelper>, WSHelperClient.WSHelper.IWSHelper 

    public WSHelperClient() 
    

    public WSHelperClient(string endpointConfigurationName) : 
            base(endpointConfigurationName) 
    

    public WSHelperClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) 
    

    public WSHelperClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) 
    

    public WSHelperClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress) 
    

    public WSHelperClient.WSHelper.PowerShellResponse ConvertUserMailboxToShared(string email) 
        return base.Channel.ConvertUserMailboxToShared(email);
    

    public System.Threading.Tasks.Task<WSHelperClient.WSHelper.PowerShellResponse> ConvertUserMailboxToSharedAsync(string email) 
        return base.Channel.ConvertUserMailboxToSharedAsync(email);
    

    public WSHelperClient.WSHelper.PowerShellResponse RemoveUserLicences(string upn) 
        return base.Channel.RemoveUserLicences(upn);
    

    public System.Threading.Tasks.Task<WSHelperClient.WSHelper.PowerShellResponse> RemoveUserLicencesAsync(string upn) 
        return base.Channel.RemoveUserLicencesAsync(upn);
    

    public WSHelperClient.WSHelper.PowerShellResponse RemoveMailboxFromAddressBook(string email) 
        return base.Channel.RemoveMailboxFromAddressBook(email);
    

    public System.Threading.Tasks.Task<WSHelperClient.WSHelper.PowerShellResponse> RemoveMailboxFromAddressBookAsync(string email) 
        return base.Channel.RemoveMailboxFromAddressBookAsync(email);
    

【问题讨论】:

【参考方案1】:

问题是我将我的项目命名为 WSHelperClient 并且与服务代码冲突。所以我打电话给我的客户 WSHelperWindowsClient,它解决了这个问题。

【讨论】:

以上是关于添加的服务引用的自动生成代码中的循环基类依赖错误的主要内容,如果未能解决你的问题,请参考以下文章

由于循环依赖错误,无法添加对项目的引用

添加服务引用时出错:类型是不支持的递归集合数据协定

自定义工具错误: 无法生成服务引用的代码VS2012

C#调用WCF问题汇总

工厂方法

C++循环依赖