.NET WCF 오류를 생성하는 잘못된 비누 1.1faultcode 값
-
09-06-2019 - |
문제
나는 실험과 함께 사용하여 FaultException 및 FaultException<T> 최고를 결정하기 위해 사용 패턴에서의 응용 프로그램.우리가 지원하는 데 필요 WCF 뿐만 아니라 비 WCF 서비스 소비자/클라이언트,비누를 포함하여 1.1 및 비누 1.2 클라이언트입니다.
참고:사용 FaultExceptions 와 wsHttpBinding 결과에 비누 1.2 의미론을 사용하는 반면 FaultExceptions 와 basicHttpBinding 결과에 비누 1.1 의미입니다.
나는 다음 코드를 사용하면을 던져 FaultException<FaultDetails>:
throw new FaultException<FaultDetails>(
new FaultDetails("Throwing FaultException<FaultDetails>."),
new FaultReason("Testing fault exceptions."),
FaultCode.CreateSenderFaultCode(new FaultCode("MySubFaultCode"))
);
이 FaultDetails 클래스는 단순한 테스트 등을 포함하는 문자열"메시지"속으로 아래에 볼 수 있습니다.
을 사용할 때 wsHttpBinding 응답:
<?xml version="1.0" encoding="utf-16"?>
<Fault xmlns="http://www.w3.org/2003/05/soap-envelope">
<Code>
<Value>Sender</Value>
<Subcode>
<Value>MySubFaultCode</Value>
</Subcode>
</Code>
<Reason>
<Text xml:lang="en-US">Testing fault exceptions.</Text>
</Reason>
<Detail>
<FaultDetails xmlns="http://schemas.datacontract.org/2004/07/ClassLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Message>Throwing FaultException<FaultDetails>.</Message>
</FaultDetails>
</Detail>
이 보이는 바에 따르면 비누 1.2specs.메인/root""코드는"보낸 사람",는"하위"의"MySubFaultCode".는 경우 서비스 소비자/클라이언트가 사용하여 WCF FaultException 클라이언트 측에서 또한 모방 동일한 구조를 가진 faultException.코드입니다.이름는"보낸 사람"과 faultException.코드입니다.부속 코드.이름"MySubFaultCode".
을 사용할 때 basicHttpBinding 응답:
<?xml version="1.0" encoding="utf-16"?>
<s:Fault xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<faultcode>s:MySubFaultCode</faultcode>
<faultstring xml:lang="en-US">Testing fault exceptions.</faultstring>
<detail>
<FaultDetails xmlns="http://schemas.datacontract.org/2004/07/ClassLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Message>Throwing FaultException<FaultDetails>.</Message>
</FaultDetails>
</detail>
</s:Fault>
이는 잘 보이지 않는다.보고 SOAP1.1 양가를 보"faultcode"의 값을"s:Client.MySubFaultCode"내가 사용하는 경우 FaultCode.CreateSenderFaultCode(새로운 FaultCode("MySubFaultCode")).또한 WCF 클라이언트는 잘못된 구조입니다.이 faultException.코드입니다.이름은"MySubFaultCode"대신에"보낸 사람",그리고 faultException.코드입니다.부속 코드는 null 을 대신 faultException.코드입니다.부속 코드.이름"MySubFaultCode".또한,faultException.코드입니다.IsSenderFault 거짓입니다.
비슷한 사용할 때 문제가 FaultCode.CreateReceiverFaultCode(새로운 FaultCode("MySubFaultCode")):
- 예상대로 작동 비누 1.2
- 생성"s:MySubFaultCode"대신에"s:Server.MySubFaultCode"및 faultException.코드입니다.IsReceiverFault 거짓을 위한 비누 1.1
이 항목을 게시하여 다른 사람에 http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=669420&SiteID=1 2006 년에 그리고 아무 대답했습니다.나는 그것을 찾을 생각하는 것은 매우 어려운 중 하나이다.
여기에는 다른 사람이 하는 유사한 문제점: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3883110&SiteID=1&mode=1
Microsoft 연결 bug: https://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=367963
는 방법에 대한 설명 오류를 작동해야 합: http://blogs.msdn.com/drnick/archive/2006/12/19/creating-faults-part-3.aspx
내가 뭔가 잘못된 또는 이것이 진정으로그 WCF?
해결책
이것은 현재 해결 방법:
/// <summary>
/// Replacement for the static methods on FaultCode to generate Sender and Receiver fault codes due
/// to what seems like bugs in the implementation for basicHttpBinding (SOAP 1.1). wsHttpBinding
/// (SOAP 1.2) seems to work just fine.
///
/// The subCode parameter for FaultCode.CreateReceiverFaultCode and FaultCode.CreateSenderFaultCode
/// seem to take over the main 'faultcode' value in the SOAP 1.1 response, whereas in SOAP 1.2 the
/// subCode is correctly put under the 'Code->SubCode->Value' value in the XML response.
///
/// This workaround is to create the FaultCode with Sender/Receiver (SOAP 1.2 terms, but gets
/// translated by WCF depending on the binding) and an agnostic namespace found by using reflector
/// on the FaultCode class. When that NS is passed in WCF seems to be able to generate the proper
/// response with SOAP 1.1 (Client/Server) and SOAP 1.2 (Sender/Receiver) fault codes automatically.
///
/// This means that it is not possible to create a FaultCode that works in both bindings with
/// subcodes.
/// </summary>
/// <remarks>
/// See http://stackoverflow.com/questions/65008/net-wcf-faults-generating-incorrect-soap-11-faultcode-values
/// for more details.
/// </remarks>
public static class FaultCodeFactory
{
private const string _ns = "http://schemas.microsoft.com/ws/2005/05/envelope/none";
/// <summary>
/// Creates a sender fault code.
/// </summary>
/// <returns>A FaultCode object.</returns>
/// <remarks>Does not support subcodes due to a WCF bug.</remarks>
public static FaultCode CreateSenderFaultCode()
{
return new FaultCode("Sender", _ns);
}
/// <summary>
/// Creates a receiver fault code.
/// </summary>
/// <returns>A FaultCode object.</returns>
/// <remarks>Does not support subcodes due to a WCF bug.</remarks>
public static FaultCode CreateReceiverFaultCode()
{
return new FaultCode("Receiver", _ns);
}
}
슬프게 표시되지 않은 방법을 사용하 subcodes 파괴하지 않고 하나 SOAP1.1 1.2 클라이언트입니다.
사용하는 경우에는 코드입니다.부속 코드에 구문을 만들 수 있습 SOAP1.1 호환 faultcode 값 그러나 그것은 휴식을 비누 1.2.
당신이 사용하는 경우 적절한 부속 코드 지원합니다.NET(중 하나를 통해 정적 FaultCode 방법 중 하나 또는 overloads)휴식을 비누 1.1 하지만 작품에서 비누 1.2.
다른 팁
응답에서 마이크로소프트:
로에서 설명 http://msdn.microsoft.com/en-us/library/ms789039.aspx, 기는 두 가지 방법을 설명에서 비누 1.1specification 사용자 지정 오류 코드:
(1)사용하여"dot"표기법으로 설명할
(2)정의 완전히 새로운 고장 코드
불행하게도,the"dot"표기는 피해야 합니다,그것의 사용은 권장하지 않에 WS-I 기본 프로필 사양에 있습니다.기본적으로,이 의미 없다는 것을 실제 해당하는 비누 1.2 잘못 부속 코드를 사용할 때 비누 1.1.
그래서 때를 생성 오류,아야 할 것이다 인식하고의 MessageVersion 에 정의된 바인딩 및 생성 faultcodes 니다.
"때문에 보낸 사람"과"수신기"지 유 효하는 오류 코드를 비누 1.1 없으나 실제 해당하는 결함 부속 코드,사용하지 말아야 하 CreateSenderFaultCode 및 CreateReceiverFaultCode 방법을 생성할 때 사용자 정의 오류에 대한 코드를 비누 1.1.
대신,당신이 정의하는 데 필요한 자신의 faultcode 사용하여 당신의 자신의 네임스페이스 이름:
FaultCode customFaultCode=new FaultCode(하 여,faultNamespace);