c# - Configuration for WCF service in windows form application -


i'm trying run simple calculator web service in windows form application. during applications start got error:

an unhandled exception of type 'system.invalidoperationexception' occurred in system.servicemodel.dll

additional information: service 'calculatorwcf.calculatorservice' has 0 application (non-infrastructure) endpoints. might because no configuration file found application, or because no service element matching service name found in configuration file, or because no endpoints defined in service element.

i suppose wrong configuration file. problem?

form1 code:      namespace calculatorwcf     {         partial class form1         {             /// <summary>             /// required designer variable.             /// </summary>             private system.componentmodel.icontainer components = null;              /// <summary>             /// clean resources being used.             /// </summary>             /// <param name="disposing">true if managed resources should disposed; otherwise, false.</param>             public servicehost servicehost = null;               public void startwcfcalculator()             {                 if (servicehost != null)                 {                     servicehost.close();                 }                  // create servicehost calculatorservice type ,                  // provide base address.                 servicehost = new servicehost(typeof(calculatorservice));                  // open servicehostbase create listeners , start                  // listening messages.                 servicehost.open();                }               protected override void dispose(bool disposing)             {                 if (disposing && (components != null))                 {                     components.dispose();                 }                 base.dispose(disposing);             }              #region windows form designer generated code              /// <summary>             /// required method designer support - not modify             /// contents of method code editor.             /// </summary>             private void initializecomponent()             {                 this.suspendlayout();                 //                  // form1                 //                  this.autoscaledimensions = new system.drawing.sizef(6f, 13f);                 this.autoscalemode = system.windows.forms.autoscalemode.font;                 this.clientsize = new system.drawing.size(563, 446);                 this.name = "form1";                 this.text = "form1";                 this.load += new system.eventhandler(this.form1_load);                 this.resumelayout(false);              }              #endregion         }     } 

service code:

namespace calculatorwcf {       [servicecontract(namespace = "http://microsoft.servicemodel.samples")]     public interface icalculator     {         [operationcontract]         double add(double n1, double n2);         [operationcontract]         double subtract(double n1, double n2);         [operationcontract]         double multiply(double n1, double n2);         [operationcontract]         double divide(double n1, double n2);     }      public class calculatorservice : icalculator     {         // implement icalculator methods.         public double add(double n1, double n2)         {             double result = n1 + n2;             return result;         }          public double subtract(double n1, double n2)         {             double result = n1 - n2;             return result;         }          public double multiply(double n1, double n2)         {             double result = n1 * n2;             return result;         }          public double divide(double n1, double n2)         {             double result = n1 / n2;             return result;         }     }   } 

app.config

<?xml version="1.0" encoding="utf-8" ?> <configuration>     <startup>          <supportedruntime version="v4.0" sku=".netframework,version=v4.5" />     </startup>   <system.servicemodel>    <services>       <!-- section optional new configuration model            introduced in .net framework 4. -->       <service name="microsoft.servicemodel.samples.calculatorservice"                behaviorconfiguration="calculatorservicebehavior">         <host>           <baseaddresses>             <add baseaddress="http://localhost:8000/servicemodelsamples/service"/>           </baseaddresses>         </host>         <!-- endpoint exposed @ base address provided host: http://localhost:8000/servicemodelsamples/service  -->         <endpoint address=""                   binding="wshttpbinding"                   contract="microsoft.servicemodel.samples.icalculator" />         <!-- mex endpoint exposed @ http://localhost:8000/servicemodelsamples/service/mex -->         <endpoint address="mex"                   binding="mexhttpbinding"                   contract="imetadataexchange" />       </service>     </services>     <behaviors>       <servicebehaviors>         <behavior name="calculatorservicebehavior">           <servicemetadata httpgetenabled="true"/>           <servicedebug includeexceptiondetailinfaults="false"/>         </behavior>       </servicebehaviors>     </behaviors>   </system.servicemodel> </configuration> 

you service called calculatorwcf.calculatorservice in code not microsoft.servicemodel.samples.calculatorservice in configuration file. should correct 1 of match.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -