Investigating and Analyzing Applications - Discovering and Exposing an Service Bus Service

来源:互联网 发布:网络歌曲2006 编辑:程序博客网 时间:2024/06/09 14:35

The following topics describe how to use the Windows Azure Service Bus service registry to register service endpoints, expose them in the registry, publish WSDL metadata exchange endpoints, and locate service endpoints that have been registered to be publicly visible.

How to: Publish a Service to the Service Bus Registry

The ServiceRegistrySettings endpoint behavior gives you control over how a given service is published in the Service Registry. By default, all services are "cloaked" and are not visible in the Service Registry ATOM feed.

The following table lists the properties that you can set on the ServiceRegistrySettings endpoint:

ServiceRegistrySettingspropertiesDescription

DisplayName

This is the display name for the endpoint and is used as the <title> field for the endpoint in the discovery ATOM feed. By default, the DisplayName property is set to the last segment of the service URI.

DiscoveryMode

This property is set to the Public or Private values, with the latter being the default. If you set this property toPublic, the endpoint is published into the Service Registry ATOM feed.

To add an Application to the Service Bus registry

  1. Create an instance of the ServiceRegistrySettings behavior, using the Public parameter.

    ServiceRegistrySettings serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public);serviceRegistrySettings.DisplayName = "MyService";
  2. Add the description to the associated endpoint.

    foreach (ServiceEndpoint subscriberEndpoint in subscriberHost.Description.Endpoints){    subscriberEndpoint.Behaviors.Add(serviceRegistrySettings);}
How to: Discover and Expose a Service Bus Application

Once a service has been deployed to a Windows Azure Service Bus endpoint, you can create a client to connect to that service. However, in order to do this, you must first know the URI of the service, which you can discover in one of two ways:

  1. The creator of the service can explicitly provide the URI.

  2. You can discover the address by navigating the naming hierarchy of the service namespace under which the service has been published.

This second step occurs through the service registry, which is a database of services and their associated URIs. exposing an endpoint in the service registry, see How to: Publish a Service to the Service Bus Registry.

To discover a service that has been published in the Service Registry

  1. You can discover a published service by navigating the naming hierarchy, which can be accessed through a nested tree of Atom 1.0 feeds. Theroot feed for a given project is located at http://<service-namespace>.servicebus.windows.net/ .

    Note that, by default, services are "cloaked," and not visible in the Atom feed. A developer must explicitly decide to make the service visible. However, cloaking only makes a serviceinvisible in the Atom feed; any client that has the necessary credentials can still connect to the service if it knows the address.

How to: Expose a Metadata Endpoint

A Windows Azure Service Bus metadata endpoint is a URI that exposes additional information about a service or client application. For example, the Svcutil.exe tool uses the exposed metadata from a service to build a contract so that a developer can access that service. Without the metadata, the developer would have to gain access to the contract in some other way, such as asking the creator for a copy of it directly via e-mail. Note that you can still implement an interface without metadata: metadata just lets you easily obtain the contract if you do not already have it. Also note thatexposing a metadata endpoint differs frompublishing your interface to the ATOM feed: the metadata endpoint contains additional information about the contract, whereas publishing on the ATOM feed just lists the service URI in a publicly-accessed database.

The following is a simplified procedure for exposing metadata on an application that uses the Service Bus. For a complete discussion of metadata, see Metadata Architecture Overview in the Windows Communication Foundation (WCF) documentation.

To expose a metadata endpoint

  1. In the App.config file for the host application, add the metadata endpoint definition to the service configuration information.

    <services>  <service name="Service.EchoService">    <endpoint name="RelayEndpoint"              ... />    <endpoint name="MexEndpoint" contract="IMetadataExchange" binding="netTcpRelayBinding" bindingConfiguration="default" address="mex" />  </service></services>
  2. To add metadata publishing to the service, modify the application configuration information to include an additional behavior section.

    <system.serviceModel>  ...  <behaviors>    <endpointBehaviors>      ...    <endpointBehaviors>    <serviceBehaviors><behavior name="serviceMetadata"><serviceMetadata /></behavior></serviceBehaviors>  </behaviors></system.serviceModel>
  3. Add the metadata behavior to the service by specifying the behaviorConfiguration property in the service definition.

    <services>  <service name="Service.EchoService" behaviorConfiguration="serviceMetadata">    ...  </service></services>
    WarningWarningIf the metadata endpoint is specified with a different end-to-end security mode than the service endpoint, and uses a relative address while sharing the same base address with the service endpoint, an exception of type System.ArgumentException is thrown when you open the service host. The following error message accompanies the exception: Incompatible channel listener settings. To resolve this issue, perform one of the following workarounds:

    • Specify the address of the metadata endpoint as a fully-qualified address.

    • If you want to use a relative address for the metadata endpoint that shares a base address with the service endpoint, specify thesame end-to-end security mode for both the metadata and service endpoints. 

    • Use a relative address for the metadata endpoint with a base address that differs from the base address of the service endpoint.



原创粉丝点击