c# - WCF service not opening in the browser? -


i'm learning wcf, started creating basic host app defines class 1 method follows:

 [servicecontract()]     public interface imath     {         [operationcontract]         int add(int a, int b);     }     public class mathcalcs : imath     {         public mathcalcs()         {             console.writeline("service await 2 numbers...");         }         public int add(int a, int b)         {             return + b;         }     } 

and how configured app.config file:

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <system.servicemodel>     <services>       <service name="consolehost.mathcalcs" behaviorconfiguration="mathservicemexbehavior">         <endpoint address="http://localhost:8080/mathcalcs"                   binding="basichttpbinding"                   contract="consolehost.imath"/>         <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange"/>         <host>           <baseaddresses>             <add baseaddress="http://localhost:8080/mathcalcs"/>           </baseaddresses>         </host>       </service>     </services>     <behaviors>       <servicebehaviors>         <behavior name="mathservicemexbehavior">           <servicemetadata httpgetenabled="true"/>         </behavior>       </servicebehaviors>     </behaviors>   </system.servicemodel>   <startup>     <supportedruntime version="v4.0" sku=".netframework,version=v4.6.1" />   </startup> </configuration> 

then called service main

 using (servicehost host = new servicehost(typeof(mathcalcs)))             {                 host.open();                 console.writeline("***the service ready***");             }             console.readline(); 

but fails view metadata of service through uri http://localhost:8080/mathcalcs, i'm sure i'm following steps right book i'm reading , preceding example works fine, difference didn't separate service logic (the interface , class) in stand alone class library. missing?

the following line of code

console.readline(); 

must inside braces of using clause! when done, retry finding wsdl metadata.


Comments