A
Aimslife
Hi,
I am writing WCF based application on vs2k8. I wrote Service with name
"IService" and expose given operation,
[OperationContract]
public Result ActionPerform(string function_name, ABase obj)
{ // FOR TESTING
IResult res = null;
res = new IResult(ResultStatus.EXCEPTION, new
TestException(RelectionLibExceptionCode.CLASS_EXCEPTION,
new NotImplementedException()));
return res;
}
1. ABase is abstract class for all client classes.
2. "function_name" will contain function name that will call by
reflection for given instance.
3. Result is a class that contain four things, result
status(typeof:"ResultStatus"), result value(typeof:"ABase"), exception
message (if exception generated)(typeof:"string") and exception instance
(if exception generated)(typeof:"Exception").
I am facing "MessageSecurityException was unhandled." problem when I
have added "Exception" member in class (detail error message given
below). exception member will contain customized exception instance it
can be "TestException" (it inherits from Exception class, code snap is
given below). I have tried to add "TestException" class info in
"GetKnownType" function to inform possible instance type for serialize
engine, but I got same error message. As per my knowledge, WCF serialize
engine required known exception instance type for communicate to client.
Please guide me, How to can fix this problem? If I removed exception
member from Result class then it works fine. Can we communicate
exception to client using web-service?
Result class Code snap is given below,
[DataContract]
[KnownType("GetKnownType")]
public class Result
{
private Exception exp;
[DataMember]
public Exception ExceptionInstance
{
get { return exp; }
set { }
}
private string msg;
[DataMember]
public string Message
{
get { return msg; }
set { }
}
private ResultStatus status = ResultStatus.SUCCESS;
[DataMember]
public ResultStatus Status
{
get { return status; }
set { }
}
private IBase[] value;
[DataMember]
public IBase[] Value
{
get { return this.value; }
set { }
}
public IResult(ResultStatus status, IBase[] value)
{
this.status = status;
this.value = value;
this.msg = null;
this.exp = null;
}
public IResult(ResultStatus status, string msg, Exception exp)
{
this.status = status;
this.value = null;
this.msg = msg;
this.exp = exp;
}
public IResult(ResultStatus status, Exception exp)
{
this.status = status;
this.value = null;
this.msg = exp.Message;
this.exp = exp;
}
private static Type[] GetKnownType()
{
List<Type> type_list = new List<Type>();
type_list.Add(typeof(ProductA));
type_list.Add(typeof(ProductB));
return type_list.ToArray();
}
}
Code snap of ResultStatus is given below,
[DataContract]
public enum ResultStatus
{
SUCCESS = 0,
FAIL = -1,
EXCEPTION = -2,
}
I have customized exception classes for some other details,
"TestException" class is example,
[DataContract]
public class TestException : Exception
{
public TestException(RelectionLibExceptionCode expCode, Exception exp)
: base(exp.Message, exp)
{
this.exceptionCode = expCode;
}
}
Thanks,
-Aimslife
..
I am writing WCF based application on vs2k8. I wrote Service with name
"IService" and expose given operation,
[OperationContract]
public Result ActionPerform(string function_name, ABase obj)
{ // FOR TESTING
IResult res = null;
res = new IResult(ResultStatus.EXCEPTION, new
TestException(RelectionLibExceptionCode.CLASS_EXCEPTION,
new NotImplementedException()));
return res;
}
1. ABase is abstract class for all client classes.
2. "function_name" will contain function name that will call by
reflection for given instance.
3. Result is a class that contain four things, result
status(typeof:"ResultStatus"), result value(typeof:"ABase"), exception
message (if exception generated)(typeof:"string") and exception instance
(if exception generated)(typeof:"Exception").
I am facing "MessageSecurityException was unhandled." problem when I
have added "Exception" member in class (detail error message given
below). exception member will contain customized exception instance it
can be "TestException" (it inherits from Exception class, code snap is
given below). I have tried to add "TestException" class info in
"GetKnownType" function to inform possible instance type for serialize
engine, but I got same error message. As per my knowledge, WCF serialize
engine required known exception instance type for communicate to client.
Please guide me, How to can fix this problem? If I removed exception
member from Result class then it works fine. Can we communicate
exception to client using web-service?
Result class Code snap is given below,
[DataContract]
[KnownType("GetKnownType")]
public class Result
{
private Exception exp;
[DataMember]
public Exception ExceptionInstance
{
get { return exp; }
set { }
}
private string msg;
[DataMember]
public string Message
{
get { return msg; }
set { }
}
private ResultStatus status = ResultStatus.SUCCESS;
[DataMember]
public ResultStatus Status
{
get { return status; }
set { }
}
private IBase[] value;
[DataMember]
public IBase[] Value
{
get { return this.value; }
set { }
}
public IResult(ResultStatus status, IBase[] value)
{
this.status = status;
this.value = value;
this.msg = null;
this.exp = null;
}
public IResult(ResultStatus status, string msg, Exception exp)
{
this.status = status;
this.value = null;
this.msg = msg;
this.exp = exp;
}
public IResult(ResultStatus status, Exception exp)
{
this.status = status;
this.value = null;
this.msg = exp.Message;
this.exp = exp;
}
private static Type[] GetKnownType()
{
List<Type> type_list = new List<Type>();
type_list.Add(typeof(ProductA));
type_list.Add(typeof(ProductB));
return type_list.ToArray();
}
}
Code snap of ResultStatus is given below,
[DataContract]
public enum ResultStatus
{
SUCCESS = 0,
FAIL = -1,
EXCEPTION = -2,
}
I have customized exception classes for some other details,
"TestException" class is example,
[DataContract]
public class TestException : Exception
{
public TestException(RelectionLibExceptionCode expCode, Exception exp)
: base(exp.Message, exp)
{
this.exceptionCode = expCode;
}
}
Thanks,
-Aimslife
..