共用方式為


WebChannelFactory<TChannel> 建構函式

定義

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

多載

WebChannelFactory<TChannel>()

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

WebChannelFactory<TChannel>(Binding)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

WebChannelFactory<TChannel>(ServiceEndpoint)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

WebChannelFactory<TChannel>(String)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

WebChannelFactory<TChannel>(Type)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

WebChannelFactory<TChannel>(Uri)

使用指定的 WebChannelFactory<TChannel> 初始化 Uri 類別的新執行個體。

WebChannelFactory<TChannel>(Binding, Uri)

使用指定的繫結及 WebChannelFactory<TChannel>,初始化 Uri 類別的新執行個體。

WebChannelFactory<TChannel>(String, Uri)

使用指定的端點組態及 WebChannelFactory<TChannel>,初始化 Uri 類別的新執行個體。

WebChannelFactory<TChannel>()

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

public:
 WebChannelFactory();
public WebChannelFactory ();
Public Sub New ()

適用於

WebChannelFactory<TChannel>(Binding)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

public:
 WebChannelFactory(System::ServiceModel::Channels::Binding ^ binding);
public WebChannelFactory (System.ServiceModel.Channels.Binding binding);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : System.ServiceModel.Channels.Binding -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (binding As Binding)

參數

binding
Binding

建立通道時要使用的繫結。

範例

下列程式代碼示範如何使用這個建構函式來建立 WebChannelFactory<TChannel> ,並用它來呼叫 WCF 服務。

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();
    WebHttpBinding binding = new WebHttpBinding();
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(binding);
    cf.Endpoint.Address = new EndpointAddress("http://localhost:8000");
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()
    Dim binding As New WebHttpBinding()
    Dim cf As New WebChannelFactory(Of IService)(binding)
    cf.Endpoint.Address = New EndpointAddress("http://localhost:8000")
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

適用於

WebChannelFactory<TChannel>(ServiceEndpoint)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

public:
 WebChannelFactory(System::ServiceModel::Description::ServiceEndpoint ^ endpoint);
public WebChannelFactory (System.ServiceModel.Description.ServiceEndpoint endpoint);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : System.ServiceModel.Description.ServiceEndpoint -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (endpoint As ServiceEndpoint)

參數

endpoint
ServiceEndpoint

建立通道時要使用的端點。

範例

下列程式代碼示範如何使用這個建構函式來建立 WebChannelFactory<TChannel> ,並用它來呼叫 WCF 服務。

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    WebHttpBinding binding = new WebHttpBinding();
    ContractDescription desc = ContractDescription.GetContract(typeof(IService));
    EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8000");
    ServiceEndpoint endpoint = new ServiceEndpoint(desc, binding, endpointAddress);

    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(endpoint);
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    Dim binding As New WebHttpBinding()
    Dim desc As ContractDescription = ContractDescription.GetContract(GetType(IService))
    Dim endpointAddress As New EndpointAddress("http://localhost:8000")
    Dim endpoint As New ServiceEndpoint(desc, binding, endpointAddress)

    Dim cf As New WebChannelFactory(Of IService)(endpoint)
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

適用於

WebChannelFactory<TChannel>(String)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

public:
 WebChannelFactory(System::String ^ endpointConfigurationName);
public WebChannelFactory (string endpointConfigurationName);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : string -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (endpointConfigurationName As String)

參數

endpointConfigurationName
String

通道設定的應用程式組態檔中之名稱。

範例

下列程式代碼示範如何使用這個建構函式來建立 WebChannelFactory<TChannel> 實例,並用它來呼叫 WCF 服務。

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    // The endpoint name passed to the constructor must match an endpoint element
    // in the application configuration file
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>("MyEndpoint");
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    ' The endpoint name passed to the constructor must match an endpoint element
    ' in the application configuration file
    Dim cf As New WebChannelFactory(Of IService)("MyEndpoint")
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

備註

endpointConfigurationName 參數必須設定成和應用程式組態檔中 name 項目之 <endpoint> 屬性的值相同。

適用於

WebChannelFactory<TChannel>(Type)

初始化 WebChannelFactory<TChannel> 類別的新執行個體。

public:
 WebChannelFactory(Type ^ channelType);
public WebChannelFactory (Type channelType);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : Type -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (channelType As Type)

參數

channelType
Type

要使用的通道類型。

備註

傳遞給型別參數的型別必須是介面。

適用於

WebChannelFactory<TChannel>(Uri)

使用指定的 WebChannelFactory<TChannel> 初始化 Uri 類別的新執行個體。

public:
 WebChannelFactory(Uri ^ remoteAddress);
public WebChannelFactory (Uri remoteAddress);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : Uri -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (remoteAddress As Uri)

參數

remoteAddress
Uri

呼叫之 Web 服務的 URI。

範例

下列程式碼會示範如何使用這個建構函式來建立 WebChannelFactory<TChannel> 執行個體及呼叫服務。

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(new Uri("http://localhost:8000"));
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    Dim cf As New WebChannelFactory(Of IService)(New Uri("http://localhost:8000"))
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

適用於

WebChannelFactory<TChannel>(Binding, Uri)

使用指定的繫結及 WebChannelFactory<TChannel>,初始化 Uri 類別的新執行個體。

public:
 WebChannelFactory(System::ServiceModel::Channels::Binding ^ binding, Uri ^ remoteAddress);
public WebChannelFactory (System.ServiceModel.Channels.Binding binding, Uri remoteAddress);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : System.ServiceModel.Channels.Binding * Uri -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (binding As Binding, remoteAddress As Uri)

參數

binding
Binding

要使用的繫結。

remoteAddress
Uri

呼叫之 Web 服務的 URI。

範例

下列程式碼會示範如何使用這個建構函式來建立 WebChannelFactory<TChannel> 執行個體及呼叫服務。

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    WebHttpBinding binding = new WebHttpBinding();
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>(binding, new Uri("http://localhost:8000"));
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    Dim binding As New WebHttpBinding()
    Dim cf As New WebChannelFactory(Of IService)(binding, New Uri("http://localhost:8000"))
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

適用於

WebChannelFactory<TChannel>(String, Uri)

使用指定的端點組態及 WebChannelFactory<TChannel>,初始化 Uri 類別的新執行個體。

public:
 WebChannelFactory(System::String ^ endpointConfigurationName, Uri ^ remoteAddress);
public WebChannelFactory (string endpointConfigurationName, Uri remoteAddress);
new System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)> : string * Uri -> System.ServiceModel.Web.WebChannelFactory<'Channel (requires 'Channel : null)>
Public Sub New (endpointConfigurationName As String, remoteAddress As Uri)

參數

endpointConfigurationName
String

通道設定的應用程式組態檔中之名稱。

remoteAddress
Uri

呼叫之 Web 服務的 URI。

範例

下列程式碼會示範如何使用這個建構函式來建立 WebChannelFactory<TChannel> 執行個體及呼叫服務。

Uri baseAddress = new Uri("http://localhost:8000");
WebServiceHost host = new WebServiceHost(typeof(Service), baseAddress);
try
{
    host.Open();

    // The endpoint name passed to the constructor must match an endpoint element
    // in the application configuration file
    WebChannelFactory<IService> cf = new WebChannelFactory<IService>("MyEndpoint", new Uri("http://localhost:8000"));
    IService channel = cf.CreateChannel();
    string s;

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ");
    s = channel.EchoWithGet("Hello, world");
    Console.WriteLine("   Output: {0}", s);
}
catch (CommunicationException ex)
{
    Console.WriteLine("An exception occurred: " + ex.Message);
}
Dim baseAddress As New Uri("http://localhost:8000")
Dim host As New WebServiceHost(GetType(Service), baseAddress)
Try
    host.Open()

    ' The endpoint name passed to the constructor must match an endpoint element
    ' in the application configuration file
    Dim cf As New WebChannelFactory(Of IService)("MyEndpoint", New Uri("http://localhost:8000"))
    Dim channel As IService = cf.CreateChannel()
    Dim s As String

    Console.WriteLine("Calling EchoWithGet via HTTP GET: ")
    s = channel.EchoWithGet("Hello, world")
    Console.WriteLine("   Output:  0}", s)
Catch ex As CommunicationException
    Console.WriteLine("An exception occurred: " + ex.Message)
End Try

備註

endpointConfigurationName 參數必須設定成和應用程式組態檔中 name 項目之 <endpoint> 屬性的值相同。

適用於