オープンソースのクライアントアプリケーションで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
私は障害が常にベースの障害クラスの下に巻き込まれる "otherFault"
try
{
throw faultexcept;
}
catch (System.ServiceModel.FaultException<InvalidRepresentation> invalidRepresentationFault)
{
throw invalidRepresentationFault;
}
catch (System.ServiceModel.FaultException otherFault)
{
throw otherFault;
}
catch (Exception ex)
{
throw ex;
}
を追加しました。 マイ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クラスを定義するとき、上記の例のフォールトを適切に処理するためには、そのクラスはどのように見える必要がありますか?また、クライアントコードでどのようにFaultがスローされたのかを判断するには、 'System.ServiceModel.FaultException.CreateFault'コードで処理されていると仮定していますか? –