.NET WCF服务客户端即使SOAP响应中有数据,也会响应null值

时间:2017-02-24 18:06:07

标签: c# web-services wcf soap wsdl

我创建了一个WCF服务客户端,为我自动创建了服务引用,并且发送SOAP请求消息的工作方式正常,但是当我收到SOAP响应时,我从信封中收到数据,但服务客户端返回为null。我已经看过几个讨论这个问题的问题,它似乎总是与NameSpace问题有关,但NameSpaces似乎匹配起来。属性的名称似乎也排成一行。我有一个我收到的SOAP消息和生成的服务引用的示例:

<soapenv:Envelope xmlns:gec="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soapenv:Header />
      <soapenv:Body>
<gec:GECSNIncidentResponse>
  <AssetName>Web</AssetName>
  <RequestId>CAPINC0185961</RequestId>
  <BriefDesc>\DEV_Region\WEB\TEST_JAMS_SONIC</BriefDesc>
  <AssignedGroup>@ELEC INS IT/Operations</AssignedGroup>
  <TranStatus>SUCCESS</TranStatus>
  <RequestURL>https://gecapqa.service-now.com/nav_to.do?uri=incident.do?sys_id=443fd14b0f0df68070a401cce1050e2c</RequestURL>
  <CreatedBy />
  <Error>
  <ErrorCode />
      <ErrorDetails />
     </Error>
    </gec:GECSNIncidentResponse>
   </soapenv:Body>
</soapenv:Envelope>

这是客户:

   namespace GESonicService.GESonic_Service {


    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(Namespace="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS", ConfigurationName="GESonic_Service.GECSNIncidentWSPortType")]
    public interface GECSNIncidentWSPortType {
    [System.ServiceModel.OperationContractAttribute(Action="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS/#Open", ReplyAction="*")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
        GESonicService.GESonic_Service.OpenResponse1 Open(GESonicService.GESonic_Service.OpenRequest request);

        [System.ServiceModel.OperationContractAttribute(Action="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS/#Open", ReplyAction="*")]
        System.Threading.Tasks.Task<GESonicService.GESonic_Service.OpenResponse1> OpenAsync(GESonicService.GESonic_Service.OpenRequest request);
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1064.2")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS")]
    public partial class OpenInput : object, System.ComponentModel.INotifyPropertyChanged {

        private OpenInputTranInfo tranInfoField;

        private OpenInputTradPartInfo tradPartInfoField;

        private OpenInputRequestInfo requestInfoField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public OpenInputTranInfo TranInfo {
            get {
                return this.tranInfoField;
            }
            set {
                this.tranInfoField = value;
                this.RaisePropertyChanged("TranInfo");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public OpenInputTradPartInfo TradPartInfo {
            get {
                return this.tradPartInfoField;
            }
            set {
                this.tradPartInfoField = value;
                this.RaisePropertyChanged("TradPartInfo");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public OpenInputRequestInfo RequestInfo {
            get {
                return this.requestInfoField;
            }
            set {
                this.requestInfoField = value;
                this.RaisePropertyChanged("RequestInfo");
            }
        }

        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.Xml", "4.6.1064.2")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS")]
    public partial class OpenInputTranInfo : object, System.ComponentModel.INotifyPropertyChanged {

        private string tranIdField;

        private string interfaceTypeField;

        private string requestTypeField;

        private string tranNameField;

        public OpenInputTranInfo() {
            this.interfaceTypeField = "webservice";
            this.requestTypeField = "incident";
            this.tranNameField = "open";
        }[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string TranId {
            get {
                return this.tranIdField;
            }
            set {
                this.tranIdField = value;
                this.RaisePropertyChanged("TranId");
            }
        }[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string InterfaceType {
            get {
                return this.interfaceTypeField;
            }
            set {
                this.interfaceTypeField = value;
                this.RaisePropertyChanged("InterfaceType");
            }
        }[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public string RequestType {
            get {
                return this.requestTypeField;
            }
            set {
                this.requestTypeField = value;
                this.RaisePropertyChanged("RequestType");
            }
        }[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public string TranName {
            get {
                return this.tranNameField;
            }
            set {
                this.tranNameField = value;
                this.RaisePropertyChanged("TranName");
            }
        }

        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.Xml", "4.6.1064.2")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS")]
    public partial class OpenResponse : object, System.ComponentModel.INotifyPropertyChanged {

        private string assetNameField;

        private string requestIdField;

        private string briefDescField;

        private string assignedGroupField;

        private string tranStatusField;

        private string requestURLField;

        private string createdByField;

        private OpenResponseError errorField;

        private string originalDocumentField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string AssetName {
            get {
                return this.assetNameField;
            }
            set {
                this.assetNameField = value;
                this.RaisePropertyChanged("AssetName");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string RequestId {
            get {
                return this.requestIdField;
            }
            set {
                this.requestIdField = value;
                this.RaisePropertyChanged("RequestId");
            }
        }[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
        public string BriefDesc {
            get {
                return this.briefDescField;
            }
            set {
                this.briefDescField = value;
                this.RaisePropertyChanged("BriefDesc");
            }
        }[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
        public string AssignedGroup {
            get {
                return this.assignedGroupField;
            }
            set {
                this.assignedGroupField = value;
                this.RaisePropertyChanged("AssignedGroup");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
        public string TranStatus {
            get {
                return this.tranStatusField;
            }
            set {
                this.tranStatusField = value;
                this.RaisePropertyChanged("TranStatus");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=5)]
        public string RequestURL {
            get {
                return this.requestURLField;
            }
            set {
                this.requestURLField = value;
                this.RaisePropertyChanged("RequestURL");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=6)]
        public string CreatedBy {
            get {
                return this.createdByField;
            }
            set {
                this.createdByField = value;
                this.RaisePropertyChanged("CreatedBy");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=7)]
        public OpenResponseError Error {
            get {
                return this.errorField;
            }
            set {
                this.errorField = value;
                this.RaisePropertyChanged("Error");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=8)]
        public string OriginalDocument {
            get {
                return this.originalDocumentField;
            }
            set {
                this.originalDocumentField = value;
                this.RaisePropertyChanged("OriginalDocument");
            }
        }

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

    /// <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="urn:GECSNIncidentWS/WSDL/GECSNIncidentWS")]
    public partial class OpenResponseError : object, System.ComponentModel.INotifyPropertyChanged {

        private string errorCodeField;

        private string errorDetailsField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
        public string ErrorCode {
            get {
                return this.errorCodeField;
            }
            set {
                this.errorCodeField = value;
                this.RaisePropertyChanged("ErrorCode");
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
        public string ErrorDetails {
            get {
                return this.errorDetailsField;
            }
            set {
                this.errorDetailsField = value;
                this.RaisePropertyChanged("ErrorDetails");
            }
        }

        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.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 OpenResponse1 {

        [System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
        public GESonicService.GESonic_Service.OpenResponse GECSNIncidentResponse;

        public OpenResponse1() {
        }

        public OpenResponse1(GESonicService.GESonic_Service.OpenResponse GECSNIncidentResponse) {
            this.GECSNIncidentResponse = GECSNIncidentResponse;
        }
    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public interface GECSNIncidentWSPortTypeChannel : GESonicService.GESonic_Service.GECSNIncidentWSPortType, System.ServiceModel.IClientChannel {
    }

    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public partial class GECSNIncidentWSPortTypeClient : System.ServiceModel.ClientBase<GESonicService.GESonic_Service.GECSNIncidentWSPortType>, GESonicService.GESonic_Service.GECSNIncidentWSPortType {

        public GECSNIncidentWSPortTypeClient() {
        }

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

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

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

        public GECSNIncidentWSPortTypeClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
                base(binding, remoteAddress) {
        }        
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        GESonicService.GESonic_Service.OpenResponse1 GESonicService.GESonic_Service.GECSNIncidentWSPortType.Open(GESonicService.GESonic_Service.OpenRequest request) {
            return base.Channel.Open(request);
        }

        public GESonicService.GESonic_Service.OpenResponse Open(GESonicService.GESonic_Service.OpenInput Open1) {
            GESonicService.GESonic_Service.OpenRequest inValue = new GESonicService.GESonic_Service.OpenRequest();
            inValue.Open = Open1;
            GESonicService.GESonic_Service.OpenResponse1 retVal = ((GESonicService.GESonic_Service.GECSNIncidentWSPortType)(this)).Open(inValue);
            return retVal.GECSNIncidentResponse;
        }        
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        System.Threading.Tasks.Task<GESonicService.GESonic_Service.OpenResponse1> GESonicService.GESonic_Service.GECSNIncidentWSPortType.OpenAsync(GESonicService.GESonic_Service.OpenRequest request) {
            return base.Channel.OpenAsync(request);
        }

        public System.Threading.Tasks.Task<GESonicService.GESonic_Service.OpenResponse1> OpenAsync(GESonicService.GESonic_Service.OpenInput Open) {
            GESonicService.GESonic_Service.OpenRequest inValue = new GESonicService.GESonic_Service.OpenRequest();
            inValue.Open = Open;
            return ((GESonicService.GESonic_Service.GECSNIncidentWSPortType)(this)).OpenAsync(inValue);
        }
    }
}

我知道这是很多信息,但任何帮助都会很棒。

谢谢!

0 个答案:

没有答案