c# - WCF over net.tcp with security mode none gives exception -
we streaming data wcf using callbacks. wcf hosted in iis (default settings, added net.tcp protocols).
we trying disable security on wcf, i've set security mode "none", both on client , server, following communicationexception:
the socket connection aborted. caused error processing message or receive timeout being exceeded remote host, or underlying network resource issue. local socket timeout '00:00:59.8439844'.
i've put on tracing on service , traceviewer gives me following exception (system.servicemodel.protocolexception):
stream security required @ http://www.w3.org/2005/08/addressing/anonymous, no security context negotiated. caused remote endpoint missing streamsecuritybindingelement binding.
client program.cs:
using system; using system.servicemodel; using wcfclient.servicereference1; class program { static void main() { callback callback = new callback(); instancecontext context = new instancecontext(callback); service1client service1client = new service1client(context, "nettcpbinding_iservice1"); service1client.getdata(0); console.read(); service1client.stop(); } } internal class callback : iservice1callback { public void streamsignaldata(int[] result) { foreach (int in result) { console.writeline(datetime.now.tostring("dd.mm.yyyy hh:mm:ss.fff") + ": " + i); } } }
client app.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.servicemodel> <bindings> <nettcpbinding> <binding name="nettcpbinding_iservice1"> <security mode="none" /> </binding> </nettcpbinding> <wsdualhttpbinding> <binding name="wsdualhttpbinding_iservice1"> <reliablesession ordered="true" /> <security mode="none" /> </binding> </wsdualhttpbinding> </bindings> <client> <endpoint address="http://localhost/wcf-error/service1.svc" binding="wsdualhttpbinding" bindingconfiguration="wsdualhttpbinding_iservice1" contract="servicereference1.iservice1" name="wsdualhttpbinding_iservice1" /> <endpoint address="net.tcp://localhost/wcf-error/service1.svc" binding="nettcpbinding" bindingconfiguration="nettcpbinding_iservice1" contract="servicereference1.iservice1" name="nettcpbinding_iservice1"> </endpoint> </client> </system.servicemodel> </configuration>
wcf service1.svc.cs
using system; using system.net.security; using system.servicemodel; using system.threading; [servicecontract(sessionmode = sessionmode.required, callbackcontract = typeof(istreamcallback), protectionlevel = protectionlevel.none)] public interface iservice1 { [operationcontract] void getdata(int value); [operationcontract] void stop(); } public interface istreamcallback { [operationcontract(isoneway = true)] void streamsignaldata(int[] result); } [servicebehavior(instancecontextmode = instancecontextmode.persession)] [callbackbehavior(concurrencymode = concurrencymode.multiple)] public class service1 : iservice1 { private timer _timer; private readonly istreamcallback _callback = operationcontext.current.getcallbackchannel<istreamcallback>(); public void getdata(int value) { _timer = new timer(streamdata, null, 0, 500); } public void stop() { _timer.dispose(); } private void streamdata(object state) { int[] randomnumbers = new int[50]; random random = new random(); (int = 0; < 50; i++) { randomnumbers[i] = random.next(100); } _callback.streamsignaldata(randomnumbers); } }
wcf web.config
<?xml version="1.0"?> <configuration> <system.web> <compilation targetframework="4.0" debug="true"/> </system.web> <system.servicemodel> <bindings> <nettcpbinding> <binding name="nettcpbinding" > <security mode="none" /> </binding> </nettcpbinding> <wsdualhttpbinding> <binding name="wsdualhttpbinding"> <security mode="none" /> </binding> </wsdualhttpbinding> </bindings> <protocolmapping> <add scheme="http" binding="wsdualhttpbinding"/> </protocolmapping> <services> <service name="service"> <endpoint address="" binding="wsdualhttpbinding" bindingconfiguration="wsdualhttpbinding" name="endpointhttp" contract="wcfservice1.iservice1"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexhttpbinding" name="mex" contract="imetadataexchange" /> <endpoint binding="nettcpbinding" bindingconfiguration="nettcpbinding" name="endpointtcp" contract="wcfservice1.iservice1" /> </service> </services> <behaviors> <servicebehaviors> <behavior> <servicemetadata httpgetenabled="true" /> <servicedebug includeexceptiondetailinfaults="true" /> <userequestheadersformetadataaddress /> <datacontractserializer /> </behavior> </servicebehaviors> </behaviors> </system.servicemodel> <system.webserver> <modules runallmanagedmodulesforallrequests="true"/> </system.webserver> </configuration>
any ideas might be? of hits on google configuration on client , server should same (i.e. security none), can't seem find error. googling streamsecuritybindingelement came no explenations...
i not replicate problem have same setup , few things noticed:
create namesapace in wcf service1.svc.cs.
namespace wcfservice1 { [servicecontract(sessionmode = sessionmode.required, callbackcontract = typeof (istreamcallback), protectionlevel = protectionlevel.none)] public interface iservice1 { ..... [servicebehavior(instancecontextmode = instancecontextmode.persession)] [callbackbehavior(concurrencymode = concurrencymode.multiple)] public class service1 : iservice1 {
<service name="service">
should <service name="wcfservice1.service1">
. service name full type service.
services section in config:
<services> <service name="wcfservice1.service1"> <endpoint address="" binding="wsdualhttpbinding" bindingconfiguration="wsdualhttpbinding" name="endpointhttp" contract="wcfservice1.iservice1"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexhttpbinding" name="mex" contract="imetadataexchange" /> <endpoint binding="nettcpbinding" bindingconfiguration="nettcpbinding" name="endpointtcp" contract="wcfservice1.iservice1" /> </service> </services>
wcf service1.svc.cs
using system; using system.net.security; using system.servicemodel; using system.threading; namespace wcfservice1 { [servicecontract(sessionmode = sessionmode.required, callbackcontract = typeof (istreamcallback), protectionlevel = protectionlevel.none)] public interface iservice1 { [operationcontract] void getdata(int value); [operationcontract] void stop(); } public interface istreamcallback { [operationcontract(isoneway = true)] void streamsignaldata(int[] result); } [servicebehavior(instancecontextmode = instancecontextmode.persession)] [callbackbehavior(concurrencymode = concurrencymode.multiple)] public class service1 : iservice1 { private timer _timer; private readonly istreamcallback _callback = operationcontext.current.getcallbackchannel<istreamcallback>(); public void getdata(int value) { _timer = new timer(streamdata, null, 0, 500); } public void stop() { _timer.dispose(); } private void streamdata(object state) { int[] randomnumbers = new int[50]; random random = new random(); (int = 0; < 50; i++) { randomnumbers[i] = random.next(100); } _callback.streamsignaldata(randomnumbers); } } }
callback
make sure handle _callback.streamsignaldata(randomnumbers); when client disconnects. communication exception.
Comments
Post a Comment