ServiceMetadataBehavior.HttpGetEnabled Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy należy opublikować metadane usługi na potrzeby pobierania przy użyciu żądania 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

Wartość właściwości

true w przypadku opublikowania pliku WSDL; w przeciwnym razie , false. Wartość domyślna to false.

Przykłady

Poniższy przykład kodu przedstawia użycie elementu ServiceMetadataBehavior w pliku konfiguracji w celu włączenia obsługi metadanych dla żądań HTTP/GET i 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>

Uwagi

Jeśli wartość HttpGetUrl jest względna, adres, pod którym są publikowane metadane, jest adresem podstawowym i adresem usługi oraz ciągiem ?wsdl zapytania.

Jeśli wartość HttpGetUrl jest bezwzględna adresem, pod którym są publikowane metadane, jest wartość HttpGetUrl wartości plus ?wsdl querystring.

Jeśli na przykład adres usługi to http://localhost:8080/CalculatorService i HttpGetUrl ciąg jest pusty, adres metadanych HTTP/GET to http://localhost:8080/CalculatorService?wsdl.

Jeśli nie włączysz tej właściwości i nie zmienisz HttpGetUrl ani nie ustawisz jej na adres względny, podczas otwierania hosta usługi bez adresu podstawowego protokołu HTTP jest zgłaszany wyjątek w czasie wykonywania.

Dotyczy