WCF hosting mutiple endpoints with TCP
我在WCF上托管多个终结点时遇到问题,这给了我错误:
System.ServiceModel.AddressAlreadyInUseException: There is already a
listener on IP endpoint
0.0.0.0:808. This could happen if there is another application already listening on this endpoint or if you have multiple service endpoints
in your service host with the same IP endpoint but with incompatible
binding configurations. ---> System.Net.Sockets.SocketException: Only
one usage of each socket address (protocol/network address/port) is
normally permitted at system.Net.Sockets.Socket.DoBind(EndPoint
endPointSnapshot, SocketAddress socketAddress)
我的App.config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | <?xml version="1.0" encoding="utf-8"?> <configuration> </appSettings> <system.web> <compilation debug="true" /> <membership defaultProvider="ClientAuthenticationMembershipProvider"> <providers> </providers> </membership> <roleManager defaultProvider="ClientRoleProvider" enabled="true"> <providers> </providers> </roleManager> </system.web> <system.serviceModel> <diagnostics wmiProviderEnabled="true"> <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" /> </diagnostics> <bindings> <netTcpBinding> <binding name="TCPDefault" portSharingEnabled="true" /> </netTcpBinding> </bindings> <services> <!--Service1--> <service name="WCFLibrary.CalculatorService" behaviorConfiguration="DebugBehavior"> <host> <baseAddresses> </baseAddresses> </host> <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPDefault" name="ServiceTCPEndPoint" contract="WCFLibrary.ICalculator"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexTcpBinding" name="ServiceMexEndPoint" contract="IMetadataExchange" /> </service> <!--Service2--> <service name="WCFLibrary.MyWorldService" behaviorConfiguration="DebugBehavior"> <host> <baseAddresses> </baseAddresses> </host> <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPDefault" name="WCFLibrary.MyWorldService" contract="WCFLibrary.IMyWorld"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexTcpBinding" name="ServiceMexEndPoint" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="DebugBehavior"> <serviceMetadata/> <serviceDebug includeExceptionDetailInFaults="True" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> I'm having separate services with callbacks. Please advise. **Modified App.config** <?xml version="1.0" encoding="utf-8"?> <configuration> </appSettings> <system.web> <compilation debug="true" /> <membership defaultProvider="ClientAuthenticationMembershipProvider"> <providers> </providers> </membership> <roleManager defaultProvider="ClientRoleProvider" enabled="true"> <providers> </providers> </roleManager> </system.web> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel> <diagnostics wmiProviderEnabled="true"> <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" /> </diagnostics> <bindings> <netTcpBinding> <binding name="TCPDefault" portSharingEnabled="true" /> </netTcpBinding> </bindings> <services> <!--Service1--> <service name="WCFLibrary.CalculatorService" behaviorConfiguration="DebugBehavior"> <host> <baseAddresses> </baseAddresses> </host> <endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPDefault" name="ServiceTCPEndPoint" contract="WCFLibrary.ICalculator"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="net.tcp://localhost:8002/CalculatorService/mex" binding="mexTcpBinding" name="ServiceMexEndPoint" contract="IMetadataExchange" /> </service> <!--Service2--> <service name="WCFLibrary.MyWorldService" behaviorConfiguration="DebugBehavior"> <host> <baseAddresses> <!----> </baseAddresses> </host> <endpoint address="net.tcp://localhost/MyWorldService" binding="netTcpBinding" bindingConfiguration="TCPDefault" name="WCFLibrary.MyWorldService" contract="WCFLibrary.IMyWorld"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="net.tcp://localhost:8001/MyWorldService/mex" binding="mexTcpBinding" name="ServiceMexEndPoint" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="DebugBehavior"> <!-- To avoid disclosing metadata information, set the values below to false before deployment --> <!--<serviceMetadata httpGetEnabled="False" httpsGetEnabled="False" />--> <serviceMetadata/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="True" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> |
WCF:
http://pastebin.com/gHHRKeYZ
WindowsService:
http://pastebin.com/kjM3iRYj
看来是您的MEX端点存在问题-两个服务之间它们是相同的。尝试给他们提供不同的地址,以查看是否可以解决问题。
对于我来说,我已经更新了.net框架,并且收到此错误。我通过删除配置文件
中的listenBacklog和maxConnections属性来解决此错误
这是解决我问题的解决方案。
我的第一个猜测是,您有另一个在某个端口上侦听的应用程序,尝试将端口更改为这样的内容
在两个
上尝试另一个端口
1 |
如果成功,请尝试使用此命令
列出所有应用程序和监听端口
1 | netstat -an |