WCF Addressing In Depth Note

来源:互联网 发布:4g语音与数据 编辑:程序博客网 时间:2024/04/28 18:36

WCF Addressing In Depth

http://msdn.microsoft.com/en-us/magazine/cc163412.aspx

-Addressing Fundamentals
                                -Relative URIs (base address)
                                -Absolute URIs 
                -IIS AddressingConsiderations
                                -IIS control the base address
                                -Not only does IIS control the base address,it forces all of your endpoints to actually use the same base address(unlikeself-hosting). This means that if you do specify an absolute address for aparticular endpoint, it must start with the base address corresponding to thevirtual directory or you’ll get an exception. 
                                -Suppose you have a file named calc.svc and youplace it in a virtual directory that corresponds tohttp://localhost:8080/calcservice. The base address for this service will be http://localhost:8080/calcservice/calc.svc
                                                -If u have arelative address="secure" then absoluteaddress="http://localhost:8080/calcservice/calc.svc/secure"
                                                -If u have arelative address="mex" then absoluteaddress="http://localhost:8080/calcservice/calc.svc/mex"
                -Multiple Endpointsand Unique Addresses
                                -When exposing multiple endpoints withdifferent bindings,each endpoint address must be unique. This is because each endpointrequires a different transport listener and channel stack. 
                                                -e.g.:
                                                <services>
                                                  <servicename=”CalculatorService”>
                                                               <endpointaddress=”http://localhost:8080/calcservice”
                                                                                                 binding=”basicHttpBinding”
                                                                                                 contract=”ISimpleMath”/>
                                                               <endpointaddress=”http://localhost:8080/calcservice/secure”
                                                                                                 binding=”wsHttpBinding”
                                                                                                 contract=”ISimpleMath”/>
                                -Multiple endpoints share the same binding, youcan use the same addressacross those endpoints. 
                                                -e.g.:
                                                <services>
                                                  <servicename=”CalculatorService”>
                                                               <endpointaddress=”http://localhost:8080/calcservice”
                                                                                                 binding=”wsHttpBinding”
                                                                                                 contract=”ISimpleMath”/>
                                                               <endpointaddress=”http://localhost:8080/calcservice”
                                                                                                 binding=”wsHttpBinding”
                                                                                                 contract=”IScientific”/>
                -Logical vs. PhysicalAddresses

-When defining an endpoint for a WCF service, the "address" attribute (in case of defining it in a configuration file) is the logical address.The logical address corrsponds to the "To" header defined in WS-Addressing. Default WCF uses the same address as the physical address, butthe physical address can be set individually in the "listenUri" attribute. The physical address corrsponds to the "Via" header defined in WS-Addressing. The logical address is important when WCF should dispatch the incoming message, because default it requires an exact match between the "To" header in the message and the "address" attribute. 
                                -Windows Communication Foundation refers to thelogical address as "Address" or "Endpoint Address" and the physical address as "ListenUri".
                                -When you specify endpoint addresses like I’vedone thus far, you’re actually supplying the logical address. However, thelogical address is also used as the physical address unless otherwisespecified. 
                                -Physical Address can accomplish in configurationusing thelistenUriattribute
                                                <services>
                                                  <servicename=”CalculatorService”>
                                                               <endpointaddress=”urn:calcservice:simplemath”
                                                                                                 listenUri=”http://localhost:8080/calcservice” 
                                                                                                 binding=”wsHttpBinding”
                                                                                                 contract=”ISimpleMath”/>
                                                               <endpointaddress=”urn:calcservice:scientific”
                                                                                                 listenUri=”http://localhost:8080/calcservice” 
                                                                                                 binding=”wsHttpBinding”
                                                                                                 contract=”IScientific”/>
                -Addressing Headers
                                -In order to accommodate even moresophisticated routing anddispatching logic, you may want to annotate SOAP messages withcustom addressing headers.
                                -e.g.:
                                                -<services>
                                                                 <servicename=”CalculatorService” 
                                                                                                 behaviorConfiguration=”metadata”>
                                                                               <host>
                                                                                 <baseAddresses>
                                                                                               <addbaseAddress=”http://localhost:8080/calcservice”/>
                                                                                 </baseAddresses>
                                                                               </host>
                                                                               <endpointbinding=”wsHttpBinding” contract=”ISimpleMath”>
                                                                                 <headers>
                                                                                               <basicxmlns=”http://example.org/level”/>
                                                                                 </headers>
                                                                               </endpoint>
                                                                               <endpointbinding=”wsHttpBinding” contract=”IScientific”>
                                                                                 <headers>
                                                                                               <premiumxmlns=”http://example.org/level”/>
                                                                                 </headers>
                                                                               </endpoint>
                                                                 </service>
                -Message Filters
                                -Each endpoint actually has two filters associatedwith it—anaddress filter and a contract filter. The address filter determinesif the incoming message matches the endpoint’s "To" address and any required address headers, while the contract filter determines whether it matches the endpoint’s contract. Both filters are used by the dispatcher todetermine the destination endpoint.
                                -An easy way to change the message filter used bya service is through the AddressFilterMode property of [ServiceBehavior].AddressFilterMode comes with three values:Any, Exact, and Prefix.
                                e.g:
                                                -[ServiceBehavior(AddressFilterMode=AddressFilterMode.Prefix)]
                                                               public classCalculatorService : ISimpleMath, IScientific
                                                               {
                                -Windows Communication Foundation does come withanXPathMessageFilter, which allows you to evaluate arbitrary XPath expressionsagainst incoming messages during the matching process, single-handedly coveringcontent-driven scenarios.
                -Host NameComparisons
                                -Issue: if you want to configure the endpoint tolisten for all host names bound to a particular machine (localhost, contoso,www.contoso.com, and so on)
                                -You can further control this via theHostNameComparisonMode, which is made available on most bindings as a property.HostNameComparisonMode comes with three settings: StrongWildcard (the default),Exact, and WeakWildcard.

原创粉丝点击