오픈 소스 클라이언트 응용 프로그램에서 SOAP 오류와 관련된 자세한 정보를 추가하려고합니다. 클라이언트는 SOAP 오류가 발생할 때마다 "HandleFault"를 호출하도록 설정됩니다. 핸들 결함 방법은 다음과 같습니다WCF 오류 예외 처리 방법
여기public static void HandleFault(Message message) {
MessageFault fault = MessageFault.CreateFault(message, Int32.MaxValue);
throw System.ServiceModel.FaultException.CreateFault(fault,
typeof(PermissionDeniedFault),
typeof(EndpointUnavailable),
typeof(InvalidRepresentation),
typeof(UnwillingToPerformFault),
typeof(CannotProcessFilter),
typeof(AnonymousInteractionRequiredFault)
);
}
내가 시도하고 클라이언트에서 유효하지 않은 형식으로 변화 같은 전화 번호를 뭔가를 할 때 "메시지"로 전달되는 SOAP 장애의 일부입니다. 그 오류가 발생 될 때마다
<s:Body u:Id="_2">
<Fault xmlns="http://www.w3.org/2003/05/soap-envelope">
<Code>
<Value>Sender</Value>
<Subcode>
<Value xmlns:a="http://schemas.xmlsoap.org/ws/2004/09/transfer">a:InvalidRepresentation</Value>
</Subcode>
</Code>
<Reason>
<Text xml:lang="en-US">The request message contains errors that prevent processing the request.</Text>
</Reason>
<Detail>
<RepresentationFailures xmlns="http://schemas.microsoft.com/2006/11/ResourceManagement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AttributeRepresentationFailure>
<AttributeType>OfficePhone</AttributeType>
<AttributeValue>(123)456-7890</AttributeValue>
<AttributeFailureCode>ValueViolatesRegularExpression</AttributeFailureCode>
<AdditionalTextDetails>The specified attribute value does not satisfy the regular expression.</AdditionalTextDetails>
</AttributeRepresentationFailure>
<CorrelationId>11042dda-3ce9-4563-b59e-d1c1355819a4</CorrelationId>
</RepresentationFailures>
</Detail>
</Fault>
는
, 클라이언트는 "요청 메시지가 요청을 처리하는 방지 오류가 있습니다."다시 반환, 나는 "AttributeRepresentationFailure"노드와 자식을 포함 할 것 노드에서 클라이언트에 예외를 다시 던지기 전에.
내가 이해하는 방식은 "CreateFault"에 대한 호출이 a를 반환 할 수 있도록 해당 내용이 포함 된 Fault 클래스를 정의해야한다는 것입니다. 내가 http://msdn.microsoft.com/en-us/library/ms733841.aspx 통해 읽었지만, 클라이언트가 어떤 유형의 오류가 발생하는지 알 수 있도록 클래스를 정의하는 방법을 정확하게 이해하지 못합니다.
클라이언트 측 핸들 결함 방법에
UPDATE 나는
try
{
throw faultexcept;
}
catch (System.ServiceModel.FaultException<InvalidRepresentation> invalidRepresentationFault)
{
throw invalidRepresentationFault;
}
catch (System.ServiceModel.FaultException otherFault)
{
throw otherFault;
}
catch (Exception ex)
{
throw ex;
}
결함은 항상 기본 오류 클래스 "otherFault"에서 잡힌를 추가했다. 내가 기사에서 수학 예제를 사용하고 내 InvalidRepresentation 클래스가
[DataContract(Namespace = Constants.Rm.Namespace)]
public class InvalidRepresentation
{
private string _attributeType;
private string _attributeValue;
private string _attributeFailureCode;
private string _additionalTextDetails;
[DataMember]
public string AttributeType
{
get { return _attributeType; }
set { _attributeType = value; }
}
[DataMember]
public string AttributeValue
{
get { return _attributeValue; }
set { _attributeValue = value; }
}
[DataMember]
public string AttributeFailureCode
{
get { return _attributeFailureCode; }
set { _attributeFailureCode = value; }
}
[DataMember]
public string AdditionalTextDetails
{
get { return _additionalTextDetails; }
set { _additionalTextDetails = value; }
}
public InvalidRepresentation() {
}
}
감사합니다! 내가 올바른 방향으로 가고 있다고 생각하지만, Fault 클래스를 정의 할 때, 위에서 보낸 예제에서 오류 클래스를 올바르게 처리하려면 클래스가 어떻게 보이게해야합니까? 또한 클라이언트 코드에서 어떤 오류가 발생했는지 판단 할 수있는 방법은'System.ServiceModel.FaultException.CreateFault' 코드에서 처리했다고 가정합니다. –