添加服务引用会生成两个请求类

时间:2016-11-30 10:14:37

标签: c# wcf soap wsdl

我有一个我需要使用的WSDL,从第三方交给我,与服务通信。我右键点击了#34;参考文献"在Visual Studio(2015)中选择"添加服务参考"并指出了WSDL。服务被添加,但当我选择"在对象浏览器中查看"有很多重复的类和枚举,例如NameOfClass / NameOfClass1。

还有Request / Request1和Response / Response1。

Request1看起来像这样

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

请求看起来像这样

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

第二个请求似乎是正确的,但接口要我实现Request1。

界面如下所示

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

我在这个问题上尝试过大量的Google搜索,尝试修改配置选项,但似乎没有任何效果。

任何人都知道导致此问题的原因是什么?

2 个答案:

答案 0 :(得分:0)

This link为将来可能遇到此问题的任何人提供了解决方案!

答案 1 :(得分:0)

我在Xamarin.Android中遇到相同的问题。 当参数GenerateMessageContracttrue时,会重现此行为。将其设置为false为我解决了问题。

如果您已经添加了服务,则可以在ConnectedService.json文件中更改此值,然后更新服务。