共用方式為


ServiceMetadataBehavior.HttpGetEnabled 屬性

定義

取得或設定值,這個值會指出是否發行要使用 HTTP/GET 要求擷取的服務中繼資料。

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

屬性值

如果發行 WSDL 則為 true,否則為 false。 預設為 false

範例

下列程式碼範例會示範如何在組態檔中使用 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 查詢字串。

如果 HttpGetUrl 的值為絕對值,則發行中繼資料的位址為 HttpGetUrl 的值,外加一個 ?wsdl 查詢字串。

例如,如果服務位址為 http://localhost:8080/CalculatorServiceHttpGetUrl 為空字串,則 HTTP/GET 中繼資料位址為 http://localhost:8080/CalculatorService?wsdl

如果您沒有啟用這個屬性,也沒有變更 HttpGetUrl 或將它設定為相對位址,則在沒有使用 HTTP 的基底位址開啟服務主機時,就會在執行階段擲回例外狀況。

適用於