WCF throwing CommunicationException when FaultException is thrown -
solution:
a bit of tracing showed communicationexception being thrown because there issue exception t not serializing correctly; because, 2 layers deep, had anonymously typed object, unserializable. removing , bubbling changes appeared fix it. there somethinge else small did before that, can't remember life of me was, wasn't done in config.
i getting messages traces such as:
type 'rebuiltwcfservice.requests.helloworldrequest' data contract name 'helloworldrequest:http://schemas.datacontract.org/2004/07/rebuiltwcfservice.requests' not expected. consider using datacontractresolver or add types not known statically list of known types - example, using knowntypeattribute attribute or adding them list of known types passed datacontractserializer.
original post
i've encountered seemingly strange issue today cant't find answer to!
the problem: service throwing communicationexception when throw faultexception! does not if don't throw exception.
in service, i'm defining fault contracts:
[operationcontract] [faultcontract(typeof(faults.helloworldfault))] responses.helloworldresponse helloworld(requests.helloworldrequest parameter);
then under error conditions i'm throwing exception of correct type:
if (_errors.count() > 0) { faults.helloworldfault fault = new faults.helloworldfault(_errors); throw new faultexception<faults.helloworldfault>(fault, new faultreason("there 1 or more errors in request. check 'errors' property more detaisl")); }
and i'm catching on client end:
try { response = client.helloworld(new basicservice.helloworldrequest() { number = 49 }); client.close(); console.writeline(string.format("response message: {0}, response number: {1}", response.message, response.number)); } catch (faultexception<basicservice.helloworldfault> ex) { ... }
that seems ok me, , should work. however, go test error clauses (by providing bad data, such missing field), whole thing dies on me. when throw faultexception, service instead throws communicationexception message
an error occurred while receiving http response http://localhost:8732/design_time_addresses/rebuiltwcfservice/service1/. due service endpoint binding not using http protocol. due http request context being aborted server (possibly due service shutting down). see server logs more details.
can offer insight on one? am using basichttp binding, , i've tried wshttp. post config file upon request.
a faultexception child of communicationexception. there nothing wrong in what's happening in code.
if uncertain exception while handling, reported communicationexception. if want handle specific exception in own way, use following structure.
try { ... } catch (faultexception<mydemoexception> me) { ... } catch (faultexception fe) { ... } catch (communicationexception ce) { ... } catch (exception ex) { ... }
in above structure, exception parent of communicationexception. communicationexception parent of faultexception , on.
system.object system.exception system.systemexception system.servicemodel.communicationexception system.servicemodel.faultexception system.servicemodel.faultexception<tdetail> system.servicemodel.web.webfaultexception<t>
Comments
Post a Comment