The main point here is the same name exception: [ServiceContract] publicinterface iuserinfo { [ OperationContract] string showname (string name); [OperationContract] string showname (); } For OperationContract with the same name, if the client references the service, the
and serializable features. For the transmission representation (wire representation) generated for this type, it is as if only the datacontract feature is applied. At the same time, we still need to add the datamember feature to the members.
In the data contract of WCF, it is obvious that WCF cannot fully support the object-oriented design concept. In Chapter 2nd's description of the service contract, the inheritance level processing method of the contract already reflects the clue of this de
, the publishing service will invoke the persistent subscriber address, The event is then passed, because the persistent subscriber saves the Subscriber address to the database or disk, which improves manageability when the publishing service goes down.The above main introduction theory, the following into the practice phase, first download Servicemodelex (programming WCF Services inside the book author provides simplified WCF programming dynamic Library), Https://github.com/CaseyBurns /servicem
information on the ABCD project to facilitate cooperation. Think about this cooperation agreement, like the service agreement we mentioned here? Yes, the service agreement is actually nothing remarkable. The two companies that just signed the Cooperation Agreement are called "server" and "client" respectively ".
The service agreement tells the client which methods you can call and which data types you can use. The public and non-public interfaces allow you to call depend entirely on how the ser
client will be blocked even if only one-way calls are sent. However, once the call is put into the queue, the blocking on the client will be canceled and the execution will continue. At the same time, the service will process this operation in the background.Developers may mistakenly think that one-way operations are equivalent to concurrent calls. If the client uses the same proxy but uses multiple threads to call one-way operations, the calls on the server may be concurrent or not. In essence
service1.svc. CS file-service1 class is inherited from the iservice1.cs file's iservice1 interface, the first part of the play is half the content to the iservice1.cs file.
First, check the iservice1.cs file,It can be seen from the name that this is an interface file, which defines some interfaces and the interface declares some methods. I added two classes public class student1, public class student2, and a method public student1 student1class () for testing. The Code is as follows:View code
method Student1 Studentwritename (string name) as a test. The code is as follows: usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Runtime.Serialization;usingSystem.ServiceModel;usingSystem.ServiceModel.Web;usingSystem.Text;namespacewcfservice_1{//Note: Using the rename command on the Refactor menu, you can change the interface name "IService1" in code and configuration files at the same time. [ServiceContract] Public InterfaceIService1 {[
, you must create an interface for the service and declare the content of the external service.
Add the new interface class imoduleservice. CS in the solution, and then introduce the namespace using system. servicemodel;
The Code is as follows:
Using system;Using system. Collections. Generic;Using system. LINQ;Using system. text;Using system. servicemodel;Using wcfservicelib. model;
Namespace wcfservicelib. iservice{/// /// Interface Class/// [Servicecontract]Public interface imoduleservi
1. Create empty web project and add the following class along with its associated interface code
Public class person{Public String ID{Get;Set;}
Public string name{Get;Set;}}
[Servicecontract]Interface ipersonservice{
[Operationcontract]Person getpo ();
[Operationcontract]String sayhello (string name );
[Operationcontract]Person getperson (string ID );
[
A lot of key knowledge has been blown up before. In order to make comprehensive use of them, today, we will make a group chat application, just like the QQ group, one server, and N clients, after the server is running, each client automatically connects to the server to generate a session when it starts. As long as any client sends messages to the server, the server sends messages to all clients. Let's take a look at how to replace Socket with WCF. This example uses the following knowledge point
{ string getfullname ( string author ); [Operationcontract ()]StringGetfamilyname (StringAuthor );} Public Class Anrsservice: ianrsservicecontract{ Public String Getfullname ( String Author){ Return Author. Replace ( ' . ' , ' ' );} PublicStringGetfamilyname (StringAuthor){ReturnAuthor. Split ('.')[2];}}} The service contract is mapped to the CLR interface type. In terms of the contract, accessibility is irrelevant, be
byte streams to objects.
-By default, the primitive type is serializable,. NET FrameworkMany types are serializable.
Message mode of service operation
> Request/Reply
-Request/In the reply mode, the request sender (client application) will receive a response related to the request. This is the default mode, because it supports both input operations (one or more parameters are passed to this operation ), return operation is also supported. (This operation passes one or more parameters
use the wcftestclient tool as an example to call it. I can find that it cannot be called, and my contract is declared as follows:
Figure 1
[Operationcontract]
String getcategorybyid (INT categoryid );
[Operationcontract]
Northwind. Categories getcategorybyid1 (INT categoryid );
[Operationcontract]
Void getcategorybyid2 (INT categoryid, out nor
By default, the contract communication in WCF is the request recovery method. After the client sends a request, it can continue to execute the following code until the server replies.
In addition to request response communication, full duplex can also be used. The following is an example:
1. Add a WCF class library
2. Add the following segment in the service contract
[Servicecontract (namespace = "http://Microsoft.ServiceModel.Samples", sessionmode = sessionmode. required,Callbackcontract = typ
, server exceptions, packaged exceptions received by the client
6) These logging policies are configured in the database, and logs are stored in the storage, using the Nosql Technology of Mongodb.
In a word, service consumers and providers only need to consider how to write services, and other basic tasks such as configuration, deployment, and cross-cutting do not need to be considered. Configuration concentration is good for deployment, various logs with independent switches are good for troub
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.