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

本文详细介绍了如何使用Windows Azure Service Bus服务注册来发布服务端点、暴露服务、发布WSDL元数据和定位已注册的公开可见服务端点。包括如何设置服务注册配置,如何将服务注册到服务注册表,如何发现并访问服务,以及如何暴露元数据端点以供客户端使用。

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:

ServiceRegistrySettingsproperties Description

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. The root 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 service invisible 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 that exposing a metadata endpoint differs from publishing 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>
    
    
    WarningWarning
    If 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 the same 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.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值