質問

私の実験の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&lt;FaultDetails&gt;.</Message>
  </FaultDetails>
</Detail>

こう権利に従ってソープ1.2仕様の主要/root"コード"が"送信者"、"Subcode"の"MySubFaultCode".場合、サービスの消費者/クライアントを利用WCF FaultExceptionクライアント側のものを模倣したものと同じ構造のfaultException.コードです。名称は"送り手"とfaultException.コードです。SubCode.名称は"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&lt;FaultDetails&gt;.</Message>
    </FaultDetails>
  </detail>
</s:Fault>

このく見えません。の石鹸1.1の仕様、私は期待したのですが、"faultcode"としての価値"s:Client.MySubFaultCode"ご利用する場合は、FaultCode.CreateSenderFaultCode新FaultCode("MySubFaultCode")).また、WCFお客様が間違った構造です。のfaultException.コードです。名前は"MySubFaultCode"ではなく、"送信者"のfaultException.コードです。SubCodeがnullの場合ではなくfaultException.コードです。SubCode.名称は"MySubFaultCode".また、faultException.コードです。IsSenderFaultはfalseです。

同様の問題がFaultCode.CreateReceiverFaultCode新FaultCode("MySubFaultCode")):

  • 作品として期待されSOAP1.2
  • 成"s:MySubFaultCode"の代わりに"s:Server.MySubFaultCode"のfaultException.コードです。IsReceiverFaultがfalseの場合石鹸用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を崩さずは石鹸1.1または1.2おります。

ご利用の場合のコードです。SubCode書式を作成できソープ1.1に対応faultcode値ががまとめられることにより、石鹸1.2.

ご利用の場合は適切なsubcode支援す。当期は、静FaultCode方法または過負荷)がまとめられることにより、ソープ1.1で動作石鹸1.2.

他のヒント

対応株式会社エンパシは、Microsoft社からwindows:

として議論 http://msdn.microsoft.com/en-us/library/ms789039.aspx, があり方法の概要は、石鹸1.1の仕様のカスタム断層コード:

(1)の"ドット"の表記などについて説明していただけま

(2)を定義する全く新しい断層コード

残念ながら、"ドット"の表記は避けることが多く、ゆったりと使用することは推奨さWS-I基本プロファイル仕様となります。基本的にすることはありませんの石鹸1.2断層SubCode利用の場合石鹸1.1.

そのため、生成断層の店舗では認識しMessageVersion定義された結果をfaultcodesます。

以来、"送り手"と"受け手"のvaild断層コードソープ1.1であり実質者と同等以上の断層subcodeんのCreateSenderFaultCodeとCreateReceiverFaultCode手法の生成時にカスタム断層コードソープ1.1.

代わりに、必要な独自に定義すfaultcode、自分の名前空間名:

FaultCode customFaultCode=new FaultCode(localName、faultNamespace);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top