Search code examples
c#wcfsoapwsdl

Add service reference generates two request classes


I have a WSDL I need to use, handed to me from a 3rd party, to communicate with a service. I right-clicked "References" in Visual Studio (2015) and chose "Add Service Reference" and pointed to the WSDL. Service gets added, but when I chose the "View in Object Browser" there are a lot of duplicate classes and enums e.g. NameOfClass/NameOfClass1.

There's also Request/Request1 and Response/Response1.

Request1 looks like this

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class PublishAnsattRequest1 {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://url/ansatt/service/v1_7", Order=0)]
    public WcfServiceStatnett.AnsattService.PublishAnsattRequest PublishAnsattRequest;

    public PublishAnsattRequest1() {
    }

    public PublishAnsattRequest1(WcfServiceStatnett.AnsattService.PublishAnsattRequest PublishAnsattRequest) {
        this.PublishAnsattRequest = PublishAnsattRequest;
    }
}

Request looks like this

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1064.2")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://url/ansatt/service/v1_7")]
public partial class PublishAnsattRequest : object, System.ComponentModel.INotifyPropertyChanged {

    private BlueMsgHeaderType blueMsgHeaderField;

    private AnsattObject ansattField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://url/object/v1", Order=0)]
    public BlueMsgHeaderType BlueMsgHeader {
        get {
            return this.blueMsgHeaderField;
        }
        set {
            this.blueMsgHeaderField = value;
            this.RaisePropertyChanged("BlueMsgHeader");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Namespace="http://url/object/v1_7", Order=1)]
    public AnsattObject Ansatt {
        get {
            return this.ansattField;
        }
        set {
            this.ansattField = value;
            this.RaisePropertyChanged("Ansatt");
        }
    }

    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));
        }
    }
}

The second request seems to be the correct one, but the interface wants me to implement Request1.

The interface looks like this

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://url/ansatt/wsdl/v1_7", ConfigurationName="AnsattService.AnsattService")]
public interface AnsattService {

    // CODEGEN: Generating message contract since the operation PublishAnsatt is neither RPC nor document wrapped.
    [System.ServiceModel.OperationContractAttribute(Action="PublishAnsatt", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Periode1))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AuditInfoType1))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Periode))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AuditInfoType))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(PersonObject1))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(SystemKeyPairType))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(OrganisasjonsenhetObject))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(KodeverdiDecimalType))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(KodeverkObject))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AnsettelsesforholdType))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(PersonObject))]
    WcfServiceStatnett.AnsattService.PublishAnsattResponse1 PublishAnsatt(WcfServiceStatnett.AnsattService.PublishAnsattRequest1 request);
}

I have tried a lot of googling on this issue, tried tinkering with configuration options, but nothing seems to work.

Anyone know what causes this issue?


Solution

  • This link provided the solution for anyone who may run into this issue in the future!