summaryrefslogtreecommitdiff
path: root/qpid/doc/book/src/WCF.xml
blob: aaf54463dbff9905066d4fe73a5bbde6d5dc3958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version="1.0" encoding="utf-8"?>
<!--
 
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at
 
   http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 
-->

<section>
  <title>
    WCF
  </title>
  <section role="h1" id="WCF-Introduction">
    <title>
      Introduction
    </title>

    <para>
      WCF (<emphasis>Windows Communication Foundation)</emphasis> unifies the .Net
      communication capabilities into a single, common, general Web
      service oriented framework. A good WCF tutorial can be found
      <ulink url="http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2#WCFSilverlightIntroduction">here</ulink>.
    </para>
    <para>
      WCF separates how service logic is written from how services
      communicate with clients. Bindings are used to specify the
      transport, encoding, and protocol details required for clients
      and services to communicate with each other. Qpid provide a WCF
      binding: org.apache.qpid.wcf.model.QpidBinding. WCF Services that
      use the Qpid binding communicate through queues that are
      dynamically created on a Qpid broker.
    </para>
    <!--h1-->
  </section>
  <section role="h1" id="WCF-HowtouseQpidbinding">
    <title>
      How to use Qpid binding
    </title>

    <para>
      WCF services are implemented using:
    </para>
    <itemizedlist>
      <listitem>
	<para>A service contract with one or more operation contracts.
        </para>
      </listitem>
      <listitem>
	<para>A service implementation for those contracts.
        </para>
      </listitem>
      <listitem>
	<para>A configuration file to provide that implementation with an
          endpoint and a binding for that specific contract.
        </para>
      </listitem>
    </itemizedlist>
    <para>
      The following configuration file can be used to configure a Hello
      Service:
    </para>
    <programlisting>
&lt;configuration&gt;
  &lt;system.serviceModel&gt;   
     &lt;services&gt;
      &lt;!-- the service class --&gt; 
      &lt;service name="org.apache.qpid.wcf.demo.HelloService"&gt;
        &lt;host&gt;
          &lt;baseAddresses&gt;
            &lt;!-- Use SOAP over AMQP --&gt;
            &lt;add baseAddress="soap.amqp:///"   /&gt;
          &lt;/baseAddresses&gt;
        &lt;/host&gt;

        &lt;endpoint
          address="Hello"
          &lt;!-- We use a Qpid Binding, see below def --&gt;
          binding="customBinding"
          bindingConfiguration="QpidBinding"
          &lt;!-- The service contract --&gt;
          contract="org.apache.qpid.wcf.demo.IHelloContract"/&gt;
      &lt;/service&gt;
    &lt;/services&gt;

    &lt;bindings&gt;
      &lt;customBinding&gt;
        &lt;!-- cf def of the qpid binding --&gt; 
        &lt;binding name="QpidBinding"&gt;
          &lt;textMessageEncoding /&gt;
          &lt;!-- specify the host and port number of the broker --&gt; 
          &lt;QpidTransport            
               host="192.168.1.14"
               port="5673" /&gt;
        &lt;/binding&gt;
      &lt;/customBinding&gt;
    &lt;/bindings&gt;

    &lt;extensions&gt;
      &lt;bindingElementExtensions&gt;
        &lt;!-- use Qpid binding element: org.apache.qpid.wcf.model.QpidTransportElement --&gt; 
        &lt;add
          name="QpidTransport"
           type="org.apache.qpid.wcf.model.QpidTransportElement, qpidWCFModel"/&gt;
      &lt;/bindingElementExtensions&gt;
    &lt;/extensions&gt;

  &lt;/system.serviceModel&gt;
&lt;/configuration&gt;
    </programlisting>
    <para>
      Endpoints and bindings can also be set within the service code:
    </para>
    <programlisting>
/* set HostName, portNumber and MyService accordingly */           
Binding binding = new QpidBinding("HostName", portNumber); 
ServiceHost service = new ServiceHost(typeof(MyService), new Uri("soap.amqp:///"));
service.AddServiceEndpoint(typeof(IBooking), binding, "MyService");
service.Open();
....
    </programlisting>
    <!--h1-->
  </section>
</section>