MessageSecurityException problem in WCF

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
..
 
M

Mr. Arnold

Aimslife said:
Hi,

I am writing WCF based application on vs2k8. I wrote Service with name
"IService" and expose given operation,

Is this your first WCF solution?

If it is, then this seems overly complicated, just to be working with an
exception on the service side.
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.

No it doesn't. If your clients are internal, then throw the exception
across the service and have it logged to a log file.

http://geekswithblogs.net/frankw/ar...ailinfaults-in-wcf-service-configuration.aspx

You through the exception with a stack trace, you'll get every bit of
the message on the client side and where it went down.

That's all we ever do, but again, the clients are on a closed/protected
network.
 
A

Aimslife

Hi Arnold,
Is this your first WCF solution?

If it is, then this seems overly complicated, just to be working with an
exception on the service side.

Yes, I am newbie in WCF. Please refer me some material for log reading.


Regards,
-Aimslife
 
M

Mr. Arnold

Aimslife said:
Hi Arnold,


Yes, I am newbie in WCF. Please refer me some material for log reading.
Logging is about taking the excpetion message and other exception
information and using a 3rd party tool to log the excption or taking the
excption message and inserting records into a SQL server Table called tblLog
for rewv.

This should be done after the try/catch Abort throw\finally close on the
call to the WCF service by the client. You write the exception message at the
client to a log on exception message that has be thrown across the WCF
service to the client.
 
A

Aimslife

Logging is about taking the excpetion message and other exception
information and using a 3rd party tool to log the excption or taking the
excption message and inserting records into a SQL server Table called tblLog
for rewv.

This should be done after the try/catch Abort throw\finally close on the
call to the WCF service by the client. You write the exception message at the
client to a log on exception message that has be thrown across the WCF
service to the client.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top