Create SILVERLIGHT+WCF

Source: Internet
Author: User

To create a WCF service application

Create a Silverlight application

Create additional

To add a WCF service in a WCF service application

Referencing a class library

Add a WCF Service

The. cs file
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.Text;usingSilverlightwcf.dal;namespacesilverlightwcfservices{//Note: Using the rename command on the Refactor menu, you can change the interface name "Iworkerinfoservice" in code and configuration files at the same time. [ServiceContract] Public InterfaceIworkerinfoservice {[OperationContract] [Serviceknowntype (typeof(Workerinfo))] List<WorkerInfo>Getworkerinfo (); }}

The. svc file
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.Text;usingsil. DAL;usingsil. BLL;usingSystem.ServiceModel.Activation;namespacesil. services{//Note: Using the rename command on the Refactor menu, you can change the class name "Workerservice" in Code, SVC, and configuration files at the same time. //Note: In order to start the WCF test client to test this service, select Workerservice.svc or WorkerService.svc.cs in Solution Explorer and start debugging. //[ServiceBehavior (Includeexceptiondetailinfaults = true)]//[aspnetcompatibilityrequirements (Requirementsmode = aspnetcompatibilityrequirementsmode.allowed)]     Public classWorkerservice:iworkerservice { PublicList<workerinfo>Getallworker () {return NewBll_worker (). Getallworker (); }    }}

Add a cross-domain file

File contents:
<?XML version= "1.0" encoding= "Utf-8"?><Access-policy>  <cross-domain-access>    <Policy>      <Allow-fromhttp-request-headers="*">        <DomainURI="*"/>      </Allow-from>      <grant-to>        <ResourcePath="/"include-subpaths= "true"/>      </grant-to>    </Policy>  </cross-domain-access></Access-policy>

Adding a WCF service reference in a Silverlight application

Import namespaces

using Silverlightwcfclient.workerinfoservicereference;

code example:

         Public voidGetworkerinfo () {workerinfoserviceclient client=Newworkerinfoserviceclient (); Client.getworkerinfocompleted+ = client_getworkerinfocompleted;//vs version, this line of code will varyClient.getworkerinfoasync (); }        voidClient_getworkerinfocompleted (Objectsender, Getworkerinfocompletedeventargs e) {            if(E.error! =NULL)                return; if(E.result.count >0) {Dgworkerinfo.itemssource=e.result.tolist (); }        }

Create SILVERLIGHT+WCF

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.