c# - WCF Discovery simply doesn't work -


i'm trying add ad-hoc discovery simple wcf service-client setup (currently implemented self hosting in console app). debugging using vs2010 on windows 7, , doing whatever can find in online tutorial, still - discovery client finds nothing. needless if open client correct service endpoint can access service client.

service code:

using (var selfhost = new servicehost(typeof(renderer))) {     try     {         selfhost.open();         ...         selfhost.close(); 

service app.config:

<?xml version="1.0"?> <configuration>   <system.servicemodel>     <services>       <service name="testapp.renderer">         <host>           <baseaddresses>             <add baseaddress="http://localhost:9000" />           </baseaddresses>         </host>         <endpoint address="ws" binding="wshttpbinding" contract="testapp.irenderer"/>         <endpoint kind="udpdiscoveryendpoint"/>       </service>     </services>     <behaviors>       <servicebehaviors>         <behavior>           <servicediscovery/>           <servicemetadata httpgetenabled="true"/>         </behavior>       </servicebehaviors>     </behaviors>   </system.servicemodel> </configuration> 

client discovery code:

discoveryclient discoveryclient = new discoveryclient(new udpdiscoveryendpoint()); var criteria = new findcriteria(typeof(irenderer)) { duration = timespan.fromseconds(5) }; var endpoints = discoveryclient.find(criteria).endpoints; 

the 'endpoints' collection comes out empty. i've tried running service , client debugger, command line, admin command line - everything, no avail (all on local machine, of course, not mantion i'll need running on entire subnet eventually)

any appreciated :-)

here super simple discovery example. not use config file, c# code, can port concepts config file.

share interface between host , client program (copy each program now)

[servicecontract] public interface iwcfpingtest {   [operationcontract]   string ping(); } 

put code in host program

public class wcfpingtest : iwcfpingtest {   public const string magicstring = "djeut73bch58sb4"; // random, see if right result   public string ping() {return magicstring;} } public void wcftesthost_open() {   string hostname = system.environment.machinename;   var baseaddress = new uribuilder("http", hostname, 7400, "wcfping");   var h = new servicehost(typeof(wcfpingtest), baseaddress.uri);    // enable processing of discovery messages.  use udpdiscoveryendpoint enable listening. use endpointdiscoverybehavior fine control.   h.description.behaviors.add(new servicediscoverybehavior());   h.addserviceendpoint(new udpdiscoveryendpoint());    // enable wsdl, can use service wcfstorm, or other tools.   var smb = new servicemetadatabehavior();   smb.httpgetenabled = true;   smb.metadataexporter.policyversion = policyversion.policy15;   h.description.behaviors.add(smb);    // create endpoint   var binding = new basichttpbinding(basichttpsecuritymode.none);   h.addserviceendpoint(typeof(iwcfpingtest) , binding,   "");   h.open();   console.writeline("host open"); } 

put code in client program

private iwcfpingtest channel; public uri wcftestclient_discoverchannel() {   var dc = new discoveryclient(new udpdiscoveryendpoint());   findcriteria fc = new findcriteria(typeof(iwcfpingtest));   fc.duration = timespan.fromseconds(5);   findresponse fr = dc.find(fc);   foreach(endpointdiscoverymetadata edm in fr.endpoints)    {     console.writeline("uri found = " + edm.address.uri.tostring());   }   // here nasty part   // returning first channel, may not work.   // have logic decide uri use discovered uris   // example, may discover "127.0.0.1", 1 useless.   // also, catch exceptions when no endpoints found , try again.   return fr.endpoints[0].address.uri;   } public void wcftestclient_setupchannel() {   var binding = new basichttpbinding(basichttpsecuritymode.none);   var factory = new channelfactory<iwcfpingtest>(binding);   var uri = wcftestclient_discoverchannel();   console.writeline("creating channel " + uri.tostring());   endpointaddress ea = new endpointaddress(uri);   channel = factory.createchannel(ea);   console.writeline("channel created");   //console.writeline("pinging host");   //string result = channel.ping();   //console.writeline("ping result = " + result); } public void wcftestclient_ping() {   console.writeline("pinging host");   string result = channel.ping();   console.writeline("ping result = " + result); } 

on host, call wcftesthost_open() function, sleep forever or something.

on client, run these functions. takes little while host open, there several delays here.

system.threading.thread.sleep(8000); this.server.wcftestclient_setupchannel(); system.threading.thread.sleep(2000); this.server.wcftestclient_ping(); 

host output should like

host open 

client output should like

uri found = http://wilkesvmdev:7400/wcfping creating channel http://wilkesvmdev:7400/wcfping channel created pinging host ping result = djeut73bch58sb4 

this minimum come discovery example. stuff gets pretty complex fast.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -