English 中文(简体)
无法读到从Ap.net核心联通服务中的“FaultException”
原标题:Unable to read FaultException from an asp.net core connected service

我试图追捕WCF的客户。

生成的参考合同是:

        [System.ServiceModel.OperationContractAttribute(Action="urn:wcfname#method", ReplyAction="*")]
        [System.ServiceModel.FaultContractAttribute(typeof(Error[]), Action= "urn:wcfname#method", Name="errors")]
        [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Response))]
        [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Request))]
        service.response method(service.request request);

产生的错误类别是:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.2")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="wcf")]
    public partial class Error
    {
        
        private string errorCodeField;
        
        private string errorStringField;
        
        private string subErrorCodeField;
        
        private string offendingFieldField;
        
        private System.DateTime timeStampField;
        
        private bool timeStampFieldSpecified;
        
        private string detailStringField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(DataType="integer", Order=0)]
        public string errorCode
        {
            get
            {
                return this.errorCodeField;
            }
            set
            {
                this.errorCodeField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=1)]
        public string errorString
        {
            get
            {
                return this.errorStringField;
            }
            set
            {
                this.errorStringField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(DataType="integer", Order=2)]
        public string subErrorCode
        {
            get
            {
                return this.subErrorCodeField;
            }
            set
            {
                this.subErrorCodeField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=3)]
        public string offendingField
        {
            get
            {
                return this.offendingFieldField;
            }
            set
            {
                this.offendingFieldField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=4)]
        public System.DateTime timeStamp
        {
            get
            {
                return this.timeStampField;
            }
            set
            {
                this.timeStampField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool timeStampSpecified
        {
            get
            {
                return this.timeStampFieldSpecified;
            }
            set
            {
                this.timeStampFieldSpecified = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=5)]
        public string detailString
        {
            get
            {
                return this.detailStringField;
            }
            set
            {
                this.detailStringField = value;
            }
        }
    }

称呼 s的法典如下:

try
{
   //call the service method
}
catch (FaultException<Error[]> ex)
{
   var errorElement = XElement.Parse(ex.CreateMessageFault().GetReaderAtDetailContents().ReadOuterXml());
   var xmlDetail = (string)errorElement;
}
catch (FaultException ex)
{
   var errorElement = XElement.Parse(ex.CreateMessageFault().GetReaderAtDetailContents().ReadOuterXml());
   var xmlDetail = (string)errorElement;

}

When theres a FaultExeption<Error[]> ex, it enters there, but the error is empty string. If I comment that part, it enters on the FaultException ex, but again the error is empty string.

I m 采用netCore 3.1

问题回答

浏览FaultException表示,该频道不存在问题。 该服务局推翻了这一例外情况。 妇联的认知信息过于笼统,难以确定一个具体问题,因此,你可以按此等例外情况处理:

public class HomeService : IHomeService
      {
          public Student Get(string id)
          {
              try
              {
                  //Here, of course, an exception will be thrown
                 var result = Convert.ToInt32(id) / Convert.ToInt32("0");
 
         return new Student() { ID = Convert.ToInt32(id), Name = "hxc", SNS = "001" };
             }
             catch (Exception ex)
             {
                 var reason = new FaultReason("Exception thrown information");
 
                 var code = new FaultCode("500");
 
                 var faultException = new FaultException(reason, code, "It is GET that throws the exception");
 
                 throw faultException;
             }
         }
     }

答复中必须有多个名称空间。

see the link for a workaround: multiplenamespacesres





相关问题
WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

Access WCF service on same server

I have a .NET website with a WCF service. How do I access the current operations context of my service? One possible work around is to just make a call to the service within the app...but that seems ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

The service operation requires a transaction to be flowed

I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods). We have common 3 tier architecture. DAL (WCF) BLL Web ...

热门标签