SoapException
2 つの文字列属性を追加するために拡張しようとして立ち往生しています。から派生し
た Web サービス メソッドがあり、それを Web サービス クライアントでキャッチしたいと考えています。しかし、WebMethod にプロパティを追加して Web サービス クライアントに公開しようとすると、起動時に Web サービスが失敗し、次のメッセージが表示されます。CustomSoapException
SoapException
CustomSoapException
CustomSoapException
[XmlInclude(typeof(CustomSoapException))]
ASMX
IDictionary を実装しているため、System.Collections.IDictionary 型のメンバー System.Exception.Data をシリアル化できません。
誰かが私の内部のタイプのData
プロパティを適切にシリアル化する方法を教えてくれれば、Web サービス クライアントに正しく公開できます。プロパティ内にデータを入れるつもりさえありません。おそらく、シリアライズする必要を避けるために、拡張クラスから完全に完全に削除することができます。IDictionary
CustomSoapException
Data
これが私のコードですCustomSoapException
:
[Serializable]
public class CustomSoapException : SoapException, ISerializable
{
private string customExceptionType;
private string developerMessage;
private string userMessage;
public override System.Collections.IDictionary Data
{
get
{
return base.Data;
}
}
public CustomSoapException(): base()
{
}
public string GetDeveloperMessage()
{
return developerMessage;
}
public string GetCustomExType()
{
return customExceptionType;
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
public CustomSoapException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
public CustomSoapException(string usrMessage, string devMessage, string customExType) : base(usrMessage, SoapException.ServerFaultCode)
{
customExceptionType = customExType;
developerMessage = devMessage;
userMessage = usrMessage;
}
}
ファイル内のWebMethodコードは次のとおりです。asmx.cs
[WebMethod(EnableSession = true)]
[XmlInclude(typeof(CustomSoapException))]
public void testCustomExceptionPassing()
{
throw new CustomSoapException("user message", "developer message","customException");
}
Web サービス クライアントコード:
try
{
Srv.testCustomExceptionPassing();
}
catch (SoapException ex) {
string devMessage = (ex as Srv.CustomSoapException).GetDeveloperMessage();
}