Aracılığıyla paylaş


Nasıl yapılır: Yapılandırma İçinde Hizmet Uç Noktası Oluşturma

Uç noktalar, istemcilere Windows Communication Foundation (WCF) hizmetinin sunduğu işlevlere erişim sağlar. Göreli ve mutlak uç nokta adreslerinin birleşimini kullanarak bir hizmet için bir veya daha fazla uç nokta tanımlayabilirsiniz veya herhangi bir hizmet uç noktası tanımlamazsanız, çalışma zamanı sizin için varsayılan olarak bazılarını sağlar. Bu konu, hem göreli hem de mutlak adresler içeren bir yapılandırma dosyası kullanarak uç noktaların nasıl ekleneceğini gösterir.

Örnek 1

Aşağıdaki hizmet yapılandırması bir temel adresi ve beş uç noktayı belirtir.

<configuration>

  <appSettings>
    <!-- use appSetting to configure base address provided by host -->
    <add key="baseAddress" value="http://localhost:8000/servicemodelsamples/service" />
  </appSettings>

  <system.serviceModel>
    <services>
    <!-- This section is optional with the default configuration introduced in .NET Framework 4. -->
      <service name="Microsoft.ServiceModel.Samples.CalculatorService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="/test"
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="http://localhost:8001/hello/servicemodelsamples"
                  binding="wsHttpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="net.tcp://localhost:9000/servicemodelsamples/service"
                  binding="netTcpBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <!-- the mex endpoint is another relative address exposed at
             http://localhost:8000/ServiceModelSamples/service/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

</configuration>

Örnek 2

Temel adres, aşağıdaki örnekte gösterildiği gibi service/host/baseAddresses altında öğesi kullanılarak add belirtilir.

<service
    name="Microsoft.ServiceModel.Samples.CalculatorService">
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
    </baseAddresses>
  </host>
</service>

Örnek 3

Aşağıdaki örnekte gösterilen ilk uç nokta tanımı göreli bir adres belirtir; bu da uç nokta adresinin Tekdüzen Kaynak Tanımlayıcısı (URI) oluşturma kurallarına göre temel adresin ve göreli adresin birleşimi olduğu anlamına gelir. Göreli adres boş (""), bu nedenle uç nokta adresi temel adresle aynıdır. Gerçek uç nokta adresi şeklindedir http://localhost:8000/servicemodelsamples/service.

<endpoint address=""
    binding="wsHttpBinding"
    contract="Microsoft.ServiceModel.Samples.ICalculator" />

Örnek 4

İkinci uç nokta tanımı, aşağıdaki örnek yapılandırmada gösterildiği gibi göreli bir adres de belirtir. Göreli adres olan "test", temel adrese eklenir. Gerçek uç nokta adresi şeklindedir http://localhost:8000/servicemodelsamples/service/test.

<endpoint address="/test"
    binding="wsHttpBinding"
    contract="Microsoft.ServiceModel.Samples.ICalculator" />

Örnek 5

Üçüncü uç nokta tanımı, aşağıdaki örnek yapılandırmada gösterildiği gibi mutlak bir adres belirtir. Temel adres, adreste rol oynamaz. Gerçek uç nokta adresi şeklindedir http://localhost:8001/hello/servicemodelsamples.

<endpoint address="http://localhost:8001/hello/servicemodelsamples"
    binding="wsHttpBinding"
    contract="Microsoft.ServiceModel.Samples.ICalculator" />

Örnek 6

Dördüncü uç nokta adresi mutlak bir adres ve farklı bir aktarım (TCP) belirtir. Temel adres, adreste rol oynamaz. Gerçek uç nokta adresi net.tcp://localhost:9000/servicemodelsamples/service şeklindedir.

<endpoint address="net.tcp://localhost:9000/servicemodelsamples/service"
    binding="netTcpBinding"
    contract="Microsoft.ServiceModel.Samples.ICalculator" />

Örnek 7

Çalışma zamanı tarafından sağlanan varsayılan uç noktaları kullanmak için kodda veya yapılandırma dosyasında herhangi bir hizmet uç noktası belirtmeyin. Bu örnekte çalışma zamanı, hizmet açıldığında varsayılan uç noktaları oluşturur. Varsayılan uç noktalar, bağlamalar ve davranışlar hakkında daha fazla bilgi için bkz. WCF Hizmetleri için Basitleştirilmiş Yapılandırma ve Basitleştirilmiş Yapılandırma.

<configuration>

  <appSettings>
    <!-- use appSetting to configure base address provided by host -->
    <add key="baseAddress" value="http://localhost:8000/servicemodelsamples/service" />
  </appSettings>

  <system.serviceModel>
    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

</configuration>