2010-12-16 97 views
1

我不知道它是否可以定義某種類型的別名(例如在Spring.NET)有較短因而不易出錯的configs的,所以不是這樣:WCF服務類型別名

<service behaviorConfiguration="ListenerBehavior" name="Corporation.Solution.Project.Namespace.GenericClass`1[[OtherCorp.Framework.Long.Class.Name, OtherCorp.Framework.Another.Long.Class.Name, Version=3.0.0.39, Culture=neutral, PublicKeyToken=null]]"> 
    <host> 
    <baseAddresses> 
     <add baseAddress="net.tcp://localhost:9485/Listener" /> 
    </baseAddresses> 
    </host> 
</service> 

我會這樣的事情:

<service behaviorConfiguration="ListenerBehavior" name="ServiceTypeAlias"> 
    <host> 
    <baseAddresses> 
     <add baseAddress="net.tcp://localhost:9485/Listener" /> 
    </baseAddresses> 
    </host> 
</service> 

謝謝。

回答

0

你可以去團結,使您可以使用類型別名

看一看:

http://msdn.microsoft.com/en-us/library/ff660933(PandP.20).aspx#_Type_Aliases

你有下面的添加到您的配置文件來定義你想要的別名使用

<unity> 
<typeAliases> 
    <typeAlias alias="MyTypeAlias" type="ProductModel.IProduct, ProductModel"/> 
</typeAliases> 
</unity> 

typeAlias元素給出一個類型的'短名稱'。這個'短名'可以用來指向配置文件中任何地方的這種類型。

+0

是的,但我怎麼能在我的WCF服務xml配置中使用這些類型的別名? – zzandy 2010-12-16 16:26:59

+0

我編輯了我的答案 – 2010-12-16 16:47:55

+0

事實上,定義爲統一的類型別名可以在所有配置中使用,即使在WCF的中也是如此。只有我們使用Spring.NET的問題。但是,謝謝。 – zzandy 2010-12-21 15:38:26