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