WCF step by step: Improves the helloworld Program

Source: Internet
Author: User
Generate the token tool. As I said, this will cause some trouble for our enterprise development. The service reference must be updated manually to change the interface of the server service. Another problem is that our client will depend on our business logic layer. In this way, the client needs to include the logical assembly (DLL) during deployment ). In fact, for distributed programs, the business logic is completed on the server, so the DLL containing the business logic is not necessary to be deployed on the client, as long as the client contains the corresponding data and service contract.
This example allows us to solve these two problems. First, we separate the implementation of the Data contract and service contract from the service into different DLL, separating data from service contracts into different DLL is because our data entity classes need to act as data exchange carriers at various levels. The service contract is used only when the client interacts with the server. Therefore, the service contract is separated. From the dependency between components, we can also see that the data contract component is referenced by many components, the service contract is not required in many places.

Our solution looks complicated, and the actual enterprise development is not simpler than this. Our demo is as realistic as possible. To solve the problem of client deployment, let shore.cnlbos.com. wcfclient only reference shore.cnblogs.com. wcfdata, shore.cnblogs.com. wcfinterface, instead of relying on shore.cnblogs.com. wcfservice. The client no longer uses the svcutil tool to generate proxy classes. Now we need to implement a proxy class manually. Check the code first.

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. servicemodel;
Using system. servicemodel. channels;
Using system. servicemodel. description;
Using shore.cnblogs.com. wcfinterface;
Using shore.cnblogs.com. wcfdata;

Namespace shore.cnblogs.com. wcfclient
{
Public class employeeserviceproxy: clientbase <iemployeeservice>, iemployeeservice
{
Public employeeserviceproxy (): Base ()
{
}

Public employeeserviceproxy (string endpointconfigname)
: Base (endpointconfigname)
{
}

Public employeeserviceproxy (binding, endpointaddress address)
: Base (binding, address)
{
}

# Region iemployeeservice members

Public void addemployee (employee em)
{
Channel. addemployee (EM );
}

Public String getempnamebyid (int id)
{
Return channel. getempnamebyid (ID );
}

# Endregion
}
}



It is very simple. You only need to inherit from the clientbase <t> class and then implement the service contract interface. Its implementation is simply to call the channel. XXX is, so we call it proxy.

Download demo

Shore comments

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.