The first step is to create a new WCF service application
The second step is to define the interface:
Modify the interface class to define the method interface default file name: IService1.cs
The third step is to implement the interface:
Implement the interface method in the Svc file, default file name: Service1.svc
Fourth step, Web. config (very important):
Basically there are problems here. To upload a simple configuration file directly, see the following code:
<?xml version="1.0"encoding="Utf-8"?><configuration> <system.web> <compilation debug="true"targetframework="4.0"/> </system.web> <system.serviceModel> <!--****************** to be hand-fitted start ******************--> &L t;services> <!--Add service-<service name="Wcfdemo.service1"behaviorconfiguration="Calculatorservicebehavior"> <!--name must be the same as the service initialized by the host instance in code behaviorconfiguration behavior configuration-"http://localhost:8000/"/> </baseAddresses> "Wcfdemo.iservice1"Wcfdemo.iservice1 for contract Interface binding="Wshttpbinding"Wshttpbinding is called over HTTP--<endpoint address=""binding="Wshttpbinding"contract="Wcfdemo.iservice1"></endpoint> </service> </services> <!--****************** to be hand-finished ******************--& Gt <!--define Calculatorservicebehavior behavior--<behaviors> <serviceBehaviors> <!--************ to match a corresponding name ****************--> <behavior name="Calculatorservicebehavior"> <!--to avoid leaking metadata information, set the following values before deployment tofalseand delete the above metadata end point--<servicemetadata httpgetenabled="true"/> <!--to receive the fault exception details for debugging, set the following values totrue。 Before deployment, set tofalseTo avoid leaking exception information--<servicedebug includeexceptiondetailinfaults="false"/> </behavior> </serviceBehaviors> </behaviors> <servicehostingenvironment Multi Plesitebindingsenabled="true"/> </system.serviceModel> <system.webServer> <modules runallmanagedmodulesforallrequests="true"/> <defaultDocument> <files> <!--Be sure to and WCF service namespaces-class is the same-- <add value="service1.svc"/> </files> </defaultDocument> </system.webServer> </configuration>
Web. config
Fifth step, build the website
If you visit your
WCF Fool Tutorial