WCF中异常发送的编程配置
我希望我的Silverlight客户端能够显示WCF调用期间服务器上发生的异常 给定在客户端上创建WCF通道的当前代码:WCF中异常发送的编程配置,wcf,wcf-behaviour,Wcf,Wcf Behaviour,我希望我的Silverlight客户端能够显示WCF调用期间服务器上发生的异常 给定在客户端上创建WCF通道的当前代码: // create the binding elements BinaryMessageEncodingBindingElement binaryMessageEncoding = new BinaryMessageEncodingBindingElement(); HttpTransportBindingElement httpTransport = new HttpTra
// 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;
在try{}catch{}块中包装Begin/End调用似乎甚至不会跳入catch{}块
如果有必要,我在客户端使用Silverlight 3。由于浏览器沙箱中的安全限制,Silverlight无法看到服务器错误主体状态代码500。要使其正常工作,您需要更改服务器端,更改它将故障返回到浏览器的方式。这里有一个详细的说明。您需要做两件事: 宣布过失例外作为合同的一部分 将异常作为错误异常抛出 [经营合同] [算术故障的故障合同类型] 公共整数运算运算运算,整数a,整数b { // ... } 抛出新的FaultException
非常感谢你的帮助。这就解决了问题。尽管如此,我还是担心web.config的设置要求:我似乎拥有完整的Version=there,这是我想要避免的,因为它是动态更新的。有没有一种方法可以忽略这个版本号?我想它仍然会绑定没有全名的类型。如果取出版本会发生什么?
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
}