Home > Net >  The use of WCF service library
The use of WCF service library

Time:09-28

1. Add a new project - create a WCF service library: MyWCFLibrary

Watch the default interface and entity class:
[1] service contract: (ServiceContract) service contracts defines the remote access objects, and to call the method,
[1] data contract: (DataContract) data contract is between the client and the server custom data types to be transmitted,

Benefits: once a declarations for DataContract, then this type can be serialized in transmitted between the client and the server,

Special note: only the declarations for DataContract objects of type can be transmitted, and only member attributes will be passed, members of the methods will not be passed, WCF to statement to provide more detail control for DataContract type, you can exclude a member outside the scope of serialization, that is to say, the client program will not be excluded from the members of any information, including the definition and data,

By default, all members of the properties are excluded, so you need to put every members declared to be transmitted DataMember

2. Add the interface and implementation classes we need

[1] change the default interface and implementation classes to IStudentService and StudentService
[2] in the interface, we can add Student entity class, and annotation data contract, and the corresponding data members,
[3] the various approaches to write the interface implementation class,

3. Modify the base address in the configuration file:

4. Add a new project - create WCF host program (in this case, we still choose the console program) : MyWCFConsoleDeploy

[1] add custom service of library reference, find the WCF service library DLL, can be added to,
Add System service library module reference [2], add references, select framework, find System. ServiceModel and can be added to,
[3] in the Main method, in accordance with the previous methods, writing to start the WCF service code, (pay attention to the introduction of the namespace),
[4] generated by an administrator after the launch, by this time there will be a error:
WCF services have zero application (infrastructure) end point...

Solution: WCF service configuration file is inside the host program, rather than a WCF service repository,
Pour the configuration file copying can just add the console applications, and run successfully,

5. Add a new project - create Windows applications: CallMyWCF

Call the way as before, need to pay attention to add WCF module references

CodePudding user response:

C # good students, the basic information
  • Related