Servislerinizi WCF ile oluşturuyorsanız, method sayınız günden güne artıyorsa karşılaşabileceğiniz olası bir problem ve çözümünden bahsedeceğim.
Visual Studio içerisinden Add Service Reference veya Update Service Reference dediğiniz zaman, svcutil.exe ile istemci sınıfı oluştururken aşağıdaki hatayı alabilirsiniz.
Cannot obtain Metadata from net.tcp://localhost:8090/MyService/Mex If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: net.tcp://localhost:8090/MyService/Mex Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:809/MyService/Mex'. There is an error in the XML document. The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered during XML processing - long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader.
Bu hatanın sebebi WCF servisinde çok fazla metot veya operasyon olmasıdır.
Çözüm:
Servisin web.config ve svcutil.exe' nin config dosyalarında aşağıdaki güncellemeleri yapmamız gerekiyor.
Service web.config:
<bindings>
<netTcpBinding>
<binding name="GenericBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name="SecureBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyService.NetTcpService" name="MyService.NetTcpService">
<endpoint address="mex" name="net.tcp" binding="netTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<endpoint address="NetTcpService" binding="netTcpBinding" bindingConfiguration="GenericBinding" name="TCPEndpoint"
contract="MyService.INetTcpService" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/MyService" />
</baseAddresses>
</host>
</service>
<service
behaviorConfiguration="MyService.WsHttpService" name="MyService.WsHttpService">
<endpoint address="mex" name="http" binding="wsHttpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
<endpoint address="WsHttpService" binding="wsHttpBinding" bindingConfiguration="SecureBinding" name="httpEndpoint"
contract="MyService.IWsHttpService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8095/MyService" />
</baseAddresses>
</host>
</service>
<services>
Svcutil.exe.config: (C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin)
Aşağıdaki içeriğin tümü ile varolan dosya güncellenmeli.
<configuration>
<system.serviceModel>
<client>
<endpoint name="net.tcp" binding="netTcpBinding" bindingConfiguration="GenericBinding"
contract="IMetadataExchange" />
<endpoint name="http" binding="wsHttpBinding" bindingConfiguration="SecureBinding" contract="IMetadataExchange" />
</client>
<bindings>
<netTcpBinding>
<binding name="GenericBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</netTcpBinding>
<wsHttpBinding>
<binding name="SecureBinding" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<transport clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
Servis config ve svcutil configteki binding isimlerinin aynı olması önemlidir.
Bu değişikliklerin ardından svcutil.exe kullanılarak istemci proxy sınıfları üretebiliriz.
Ancak halen bir sorunumuz var; Visual Studio içerisinden Add Service Reference dediğimiz zaman aynı hatayı alıyoruz. Bunun çözümü de oldukça basit. svcutil.exe.config dosyasında yaptığımız değişikliği, devenv.exe.config (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE) dosyasında da yapmamız sorunumuzu çözecektir.