共用方式為


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 查詢字串。

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

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

適用於