WCF Instance App

Source: Internet
Author: User

with a brief introduction to WCF in the previous article, here's a small example of how to build and apply a WCF application. 1. Add a WCF service: 2. Open the newly created service interface Ishowmyname and add the method (be careful not to discard the service tag or access it):
    
3. Add a method to implement the service:
    
4. Look in the browser as shown to indicate success:
    
5. Publish it in IIS so that the server is configured.
6. Client configuration, the first thing to do is to add the configuration file:(1 ) Configure the Web. config

< Configuration >

< system.web >

< compilation Debug="true" targetframework="4.0" />

</ system.web >

< System.ServiceModel >

< Behaviors >

< servicebehaviors >

< Behavior name="">

< Servicemetadata httpgetenabled="true" />

< Servicedebug includeexceptiondetailinfaults="false" />

</ Behavior >

</ servicebehaviors >

</ Behaviors >

< servicehostingenvironment multiplesitebindingsenabled="true" />

< Bindings >

< BasicHttpBinding >

< binding name="basichttpbinding_default"

closetimeout="00:01:00" opentimeout=" c15>00:01:00" receivetimeout="00:10:00"

            sendtimeout = " Span style= "Color:blue" >00:01:00 "&NBSP; AllowCookies = "false " &NBSP; bypassproxyonlocal = "false "

            hostnamecomparisonmode = "strongwildcard " &NBSP; maxbuffersize = "65536 "

            maxbufferpoolsize = "524288 " &NBSP; = "65536 " &NBSP; messageencoding = "text "

            textencoding = "utf-8 "&NBSP; transfermode = "buffered "   usedefaultwebproxy = " true ">

           < readerquotas maxdepth = " 32 "&NBSP; Maxstringcontentlength = "8192 " &NBSP; maxarraylength = " Span style= "Color:blue" >16384 "

maxbytesperread="4096" maxnametablecharcount=" c8>16384" />

< Security mode="None">

< Transport clientcredentialtype="None" proxycredentialtype= "None"

Realm="" />

< message clientcredentialtype="UserName" algorithmsuite=" Default" />

</ Security >

</ binding >

</ BasicHttpBinding >

</ Bindings >

< Client >

< Endpoint

Address ="http://localhost:8080/WCFService/ShowMyName.svc?wsdl"

binding ="basichttpbinding" bindingconfiguration=" Basichttpbinding_default"

contract="contracts.ishowmyname"

name="basichttpbinding_ishowmyname" />

</ Client >

</ System.ServiceModel >

</ Configuration >

(2) client Invoke service

To add a reference to the client:

using System.ServiceModel.Channels;

Using System.ServiceModel ;          You can then add code to invoke the WCF service:
// because the service is created through a channel factory, it is necessary to instantiate the channel factory first

ChannelFactory <ishowmyname> Factory = new channelfactory <ishowmyname>("Basichttpbinding_ishowmyname");

ishowmyname MyObject = Factory. CreateChannel ();

Methods for invoking a service

string time = Myobject.showname (this. txtname.text);

WCF Instance App

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.