ServiceMetadataBehavior.HttpGetUrl 属性

定义

获取或设置进行 HTTP/GET 请求的元数据发布的位置。

public:
 property Uri ^ HttpGetUrl { Uri ^ get(); void set(Uri ^ value); };
public Uri HttpGetUrl { get; set; }
[System.ComponentModel.TypeConverter(typeof(System.UriTypeConverter))]
public Uri HttpGetUrl { get; set; }
member this.HttpGetUrl : Uri with get, set
[<System.ComponentModel.TypeConverter(typeof(System.UriTypeConverter))>]
member this.HttpGetUrl : Uri with get, set
Public Property HttpGetUrl As Uri

属性值

Uri

元数据的绝对位置或相对位置。

属性

示例

以下代码示例演示如何在配置文件中使用 ServiceMetadataBehavior,以便启用进行 HTTP/GET 和 WS-Transfer/GET 请求的元数据支持。

        // Create a new metadata behavior object and set its properties to
        // create a secure endpoint.
        ServiceMetadataBehavior sb = new ServiceMetadataBehavior();
        //sb.EnableHelpPage= true;
        //sb.HttpsGetUrl = new Uri("https://myMachineName:8036/myEndpoint");
        //myServiceHost.Description.Behaviors.Add(sb);
    }

      private void SnippetServiceMetadataBehavior()
      {
          // service for which <<indigo2>> automatically adds a
          // ServiceMetadataBehavior to publish metadata as well as
          // an HTML service help page

          // from C_HowToSecureEndpoint\cs
          // Create a new metadata behavior object and set its properties to
          // create a secure endpoint.
          ServiceMetadataBehavior sb = new ServiceMetadataBehavior();
/*          sb.EnableHelpPage = true;
          sb.enableMetadataExchange = true;
          sb.HttpsGetUrl = new Uri("https://myMachineName:8036/myEndpoint");
          myServiceHost.Description.Behaviors.Add(sb);
 */
      }

    private void Run()
    {

      // T:System.ServiceModel.ServiceMetadataBehavior
      // <Snippet#0>

      // Create a ServiceHost for the service type and use the base address from configuration.
      ServiceHost host = new ServiceHost(typeof(SampleService));
      try
      {
        ServiceMetadataBehavior metad
          = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
        if (metad == null)
          metad = new ServiceMetadataBehavior();
        metad.HttpGetEnabled = true;
        host.Description.Behaviors.Add(metad);
        host.AddServiceEndpoint(
          ServiceMetadataBehavior.MexContractName,
          MetadataExchangeBindings.CreateMexHttpBinding(),
          "mex"
        );

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

        // Close the ServiceHostBase to shutdown the service.
        host.Close();

        // </Snippet#0>

注解

如果 HttpGetUrl 的值是相对值,则发布元数据的地址为基址和服务地址加上 ?wsdl querystring。

如果 HttpGetUrl 的值是绝对值,则发布元数据的地址为此值加上 ?wsdl querystring。

例如,如果服务地址为 http://localhost:8080/CalculatorServiceHttpGetUrl 为空字符串,则 HTTP/GET 元数据地址为 http://localhost:8080/CalculatorService?wsdl

适用于