WS-I Temel Profil 1.1 Birlikte Çalışabilir Hizmetler Oluşturma

WcF hizmet uç noktasını ASP.NET Web hizmeti istemcileriyle birlikte çalışabilecek şekilde yapılandırmak için:

  • System.ServiceModel.BasicHttpBinding Hizmet uç noktanız için bağlama türü olarak türünü kullanın.

  • Hizmet uç noktanızda geri arama ve oturum sözleşmesi özelliklerini veya işlem davranışlarını kullanmayın

İsteğe bağlı olarak bağlamada HTTPS ve aktarım düzeyi istemci kimlik doğrulaması desteğini etkinleştirebilirsiniz.

sınıfının aşağıdaki özellikleri BasicHttpBinding WS-I Temel Profil 1.1'in ötesinde işlevsellik gerektirir:

WCF hizmetinin meta verilerini ASP.NET kullanılabilir hale getirmek için Web hizmeti istemci oluşturma araçlarını kullanın: Web Hizmetleri Açıklama Dil Aracı (Wsdl.exe), Web Hizmetleri Bulma Aracı (Disco.exe) ve Visual Studio'daki Web Başvurusu Ekle özelliği. Meta veri yayınlarını etkinleştirin. Daha fazla bilgi için bkz . Meta Veri Uç Noktalarını Yayımlama.

Örnek

Açıklama

Aşağıdaki örnek kod, kodda ve alternatif olarak bir yapılandırma dosyasında ASP.NET Web hizmeti istemcileri ile uyumlu bir WCF uç noktasının nasıl ekleneceğini gösterir.

Kod

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;

[ServiceContract]
public interface IEcho
{
    [OperationContract]
    string Echo(string s);
}

public class MyService : IEcho
{
    public string Echo(string s)
    {
        return s;
    }
}

class Program
{
    static void Main(string[] args)
    {
        string baseAddress = "http://localhost:8080/wcfselfhost/";
        ServiceHost host = new ServiceHost(typeof(MyService), new Uri(baseAddress));

        // Create a BasicHttpBinding instance
        BasicHttpBinding binding = new BasicHttpBinding();

        // Add a service endpoint using the created binding
        host.AddServiceEndpoint(typeof(IEcho), binding, "echo1");

        host.Open();
        Console.WriteLine("Service listening on {0} . . .", baseAddress);
        Console.ReadLine();
        host.Close();
    }
}

Imports System.Collections.Generic
Imports System.Text
Imports System.ServiceModel
Imports System.ServiceModel.Description

<ServiceContract()> _
Public Interface IEcho

    <OperationContract()> _
    Function Echo(ByVal s As String) As String

End Interface

Public Class MyService
    Implements IEcho

    Public Function Echo(ByVal s As String) As String Implements IEcho.Echo
        Return s
    End Function

End Class

Friend Class Program

    Shared Sub Main(ByVal args() As String)
        Dim baseAddress = "http://localhost:8080/wcfselfhost/"
        Dim host As New ServiceHost(GetType(MyService), _
                                    New Uri(baseAddress))

        ' Add a service endpoint using the created binding
        With host
            .AddServiceEndpoint(GetType(IEcho), _
                                New BasicHttpBinding(), _
                                "echo1")
            .Open()
            Console.WriteLine("Service listening on {0} . . .", _
                              baseAddress)
            Console.ReadLine()
            .Close()
        End With
    End Sub
End Class
<configuration>
  <system.serviceModel>
    <services>
      <service name="MyService" behaviorConfiguration="HttpGetMetadata">
        <endpoint address="echo2" contract="IEcho" binding="basicHttpBinding" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="HttpGetMetadata">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

Ayrıca bkz.