The first time I tried indigo, I used the VS 2005 pd6 + indigo SDR (2.0.40903) version. The version of the SDR is quite different from the currently released CTP version. Now I have updated my indigo runtime environment to vs2005 pd7 (8.0.50110.30, that is, the public Feb CTP version) + indigo CTP (2.0.50110.20). These two versions can work very well together. However, note that the current indigo CTP cannot run on the upcoming vs2005 beta2. When vs2005 beta2 is released, it is expected that Indigo will release a corresponding version.
Before talking about more specific topics, what is Indigo? The most official answer is: "Indigo is a set of. NET technologies used to build and run connected system. It is used to build basic communication components for service-oriented systems ". To be "inflammatory", you can use this: "Indigo is going to take over in the future. what are the communication components of distributed systems, such as asmx WebService, WSE, remoting, DCOM, and MSMQ ".
Okay. Let's take a look at several very important concepts and terminologies of Indigo. I hope to give you a clear understanding of these terms with as short a description as possible:
Service: A service. What we want to demonstrate below is to create an indigo service.
Operation: each service contains one or more operations. Operation is what the service can do.
Service Contract: used to describe the service contract. service contract is a method used by the Service to introduce and describe itself to the client. To call a service, you must first understand service contract.
Service URI: The URI of the service. To enable the client to find the service, the service must have a URI published.
Endpoint: the "Port" exposed by the service. The client connects to the service through these endpoints. A service can have one or more endpoints.
Endpoint address: the endpoint address, service URI + endpoint address, which eventually forms the full address for the client to connect to this endpoint.
Endpoint binding: The network protocol, communication mode, and Information encoding format used by the endpoint. Indigo has some standard binding built-in, such: wsprofilebinding is a binding that uses HTTP/HTTPS and text encoding. netprofiletcpbinding is a binding that uses TCP and binary encoding.
For each service, a host is required ). Indigo supports multiple host formats. The current indigo CTP supports IIS-host and self-host on WINXP/win2003, while the Longhorn platform also supports better was-host and IIS7-Host. IIS-host is similar to the current. asmx WebService, which is managed by IIS. Self-host creates a servicehost object through code, allowing any type of Programs (console, winforms ...) Can be a host. We recommend that you use IIS-host whenever possible, because it can achieve the advantages of automatic collection of processes and Process Monitoring provided by IIS. Of course, self-host is required when you need to use more efficient TCP communication/binary encoding information, we can create an indigo Windows service to implement uninterrupted services.
The endpoint setting of indigo supports the configuration file, and it is recommended that you use the configuration file instead of hard encoding. In this way, you only need to change the configuration in the configuration file to another protocol or encoding for the indigo service with the common HTTP/text encoding configuration.
OK. Let's start encoding. We first create an indigo service:
Create an ASP. Net project in vs2005 and add a class to the project (vs2005 will automatically prompt us to place the file under the app_code directory ):
[Servicecontract]
Public class mathservice
{
[Operationcontract]
Public int32 add (int32 value1, int32 value2)
{
Return value1 + value2;
}
}
As shown above, we have created a service contract, which contains an operation called add. Then, create a mathservice. SVC file in the root directory of the site. The content is as follows:
<% @ Service class = "mathservice" DEBUG = "true" Language = "CS" %>
Then we add the indigo configuration in Web. config:
<System. servicemodel>
<Services>
<Service servicetype = "mathservice">
<Endpoint contracttype = "mathservice" address = "EP1"
Bindingsectionname = "basicprofilebinding"/>
</Service>
</Services>
</System. servicemodel>
As shown above, we have created an endpoint for the service. The endpoint address is EP1, and the binding uses the basicprofilebinding that comes with Indigo.
After compiling the project, you can open IE and browse http: // localhost/mathservice. SVC/EP1 (the virtual directory of this web project on my computer is http: // localhost/mathservice). You can see some information about the indigo service.
Step 2: Create a client. Use vs2005 to create a console project. Here, we need to use a tool that comes with indigo: svcutil, which can help us automatically create a service proxy file, which will create the interfaces and classes we need to call the indigo service.
Run: svcutil "http: // localhost/mathservice. svc/EP1"/config: App. config
Svcutil automatically creates a proxy file named tempuri.org. CS and adds the file to the project. The second parameter "/config: App. config" enables svcutil to automatically write the required indigo configuration to app. config, saving us the trouble of handwriting.
Now we can encode it directly in main (). The called code is very simple:
Mathserviceproxy proxy = new mathserviceproxy ("mathservice ");
Console. writeline (proxy. Add (1, 2 ));
Run this program and we can see the correct returned result "3 ". J
OK. We completed the compilation of an indigo service and an indigo client at a very fast speed. You may think that the indigo service is no different from the web service. In fact, their differences are very large. In future articles, I will constantly show the various cool feature of indigo.