ServiceMetadataBehavior.HttpGetEnabled 属性

定义

获取或设置一个值,该值指示是否发布服务元数据以便使用 HTTP/GET 请求进行检索。Gets or sets a value that indicates whether to publish service metadata for retrieval using an HTTP/GET request.

public:
 property bool HttpGetEnabled { bool get(); void set(bool value); };
public bool HttpGetEnabled { get; set; }
member this.HttpGetEnabled : bool with get, set
Public Property HttpGetEnabled As Boolean

属性值

Boolean

如果发布 WSDL,则为 true;否则为 falsetrue if the WSDL is published; otherwise, false. 默认值为 falseThe default is false.

示例

以下代码示例演示如何在配置文件中使用 ServiceMetadataBehavior,以便启用进行 HTTP/GET 和 WS-Transfer/GET 请求的元数据支持。The following code example demonstrates the use of ServiceMetadataBehavior in a configuration file to enable metadata support for HTTP/GET and WS-Transfer/GET requests.

        // 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。If the value of HttpGetUrl is relative, the address at which the metadata is published is the base address and the service address plus a ?wsdl querystring.

如果 HttpGetUrl 的值是绝对值,则发布元数据的地址为 HttpGetUrl 值的值加上 ?wsdl querystring。If the value of HttpGetUrl is absolute the address at which the metadata is published is the value of HttpGetUrl value plus a ?wsdl querystring.

例如,如果服务地址为 http://localhost:8080/CalculatorServiceHttpGetUrl 为空字符串,则 HTTP/GET 元数据地址为 http://localhost:8080/CalculatorService?wsdlFor example, if the service address is http://localhost:8080/CalculatorService and the HttpGetUrl is an empty string, the HTTP/GET metadata address is http://localhost:8080/CalculatorService?wsdl.

如果不启用此属性且不更改 HttpGetUrl 或将其设置为相对地址,则在不使用 HTTP 基址打开服务主机的情况下会在运行时引发异常。If you do not enable this property and do not change HttpGetUrl or set it to a relative address, an exception is thrown at runtime when the service host is opened without a base address for HTTP.

适用于