Silverlightクライアントで、WCF呼び出し中にサーバーで発生した例外を表示できるようにしたいと思います。
(クライアント上で)WCFチャネルを作成するための現在のコードを考えると:
// create the binding elements
BinaryMessageEncodingBindingElement binaryMessageEncoding = new BinaryMessageEncodingBindingElement();
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue };
// add the binding elements into a Custom Binding
CustomBinding customBinding = new CustomBinding(binaryMessageEncoding, httpTransport);
// create the Endpoint URL
EndpointAddress endpointAddress = new EndpointAddress(serviceUrl);
// create an interface for the WCF service
ChannelFactory<TWcfApiEndPoint> channelFactory=new ChannelFactory<TWcfApiEndPoint>(customBinding, endpointAddress);
channelFactory.Faulted += new EventHandler(channelFactory_Faulted);
TWcfApiEndPoint client = channelFactory.CreateChannel();
return client;
例外が発生すると、「NotFound」例外が発生しますが、これは明らかに役に立ちません。例外情報を取得するにはどうすればよいですか?
このコードを使用して、上記で返されたクライアントオブジェクトを使用します。
try
{
// customFieldsBroker is the client returned above
customFieldsBroker.BeginCreateCustomField(DataTypeID, newCustomField, (result) =>
{
var response = ((ICustomFieldsBroker)result.AsyncState).EndCreateCustomField(result);
}, customFieldsBroker);
}
catch (Exception ex)
{
// would like to handle exception here
}
begin/End呼び出しをtry{}catch {}ブロックでラップしても、catch{}ブロックにジャンプすることはないようです。
重要な場合は、クライアントでSilverlight3を使用しています。