tring.Concat(WCFExpetion, CommunicationException, 网络异常,请检查地址是否正确); throw new Exception( string.Format({0}: {1}, title, tiEx.InnerException.Message), tiEx.InnerException); } else if (tiEx.InnerException is TimeoutException) { title = string.Concat(WCFExpetion, TimeoutException, 连接超时,请检查网络是否正常); throw new Exception( string.Format({0}: {1}, title, tiEx.InnerException.Message), tiEx.InnerException); } } catch (Exception ex) { throw new Exception(string.Format(WCF出现未知异常: {0}, ex.Message), ex); } finally { ((ICommunicationObject)channel).Abort(); } return methodReturn; } } }
5、建立通道工厂ChannelFactoryCreator
?
namespace ICT.RCS.Modules.Factory.ServiceProxy
{
internal static class ChannelFactoryCreator {
private static readonly Hashtable channelFactories = new Hashtable();
public static ChannelFactory
Create
(string endpointName) { if (string.IsNullOrEmpty(endpointName)) { throw new ArgumentNullException(endpointName); } ChannelFactory
channelFactory = null; if (channelFactories.ContainsKey(endpointName)) { channelFactory = channelFactories[endpointName] as ChannelFactory
; } if (channelFactory == null) { channelFactory = new ChannelFactory
(endpointName); lock (channelFactories.SyncRoot) { channelFactories[endpointName] = channelFactory; } } return channelFactory; } } }
?
6、引入工厂dll
要想使用WCF,我们以前是必须添加服务引用,而添加服务引用VS就会自动生成一个APP.CONFIG的配置文件,这个文件中配置了服务的地址以及访问协议等内容。
现在,我们需要将上面的这些内容打包成dll并添加到引用。
7、配置app.config
?