Edit

Share via


ServiceHostBase.AddServiceEndpoint Method

Definition

Adds the service endpoints to the service hosted.

Overloads

AddServiceEndpoint(ServiceEndpoint)

Adds the specified service endpoint to the hosted service.

AddServiceEndpoint(String, Binding, String)

Adds a service endpoint to the hosted service with a specified contract, binding, and endpoint address.

AddServiceEndpoint(String, Binding, Uri)

Adds a service endpoint to the hosted service with a specified contract, binding, and a URI that contains the endpoint address.

AddServiceEndpoint(String, Binding, String, Uri)

Adds a service endpoint to the hosted service with a specified contract, binding, endpoint address and URI that contains the address at which it listens.

AddServiceEndpoint(String, Binding, Uri, Uri)

Adds a service endpoint to the hosted service with the specified contract, binding, and URIs that contain the endpoint and listening addresses.

AddServiceEndpoint(ServiceEndpoint)

Adds the specified service endpoint to the hosted service.

C#
public virtual void AddServiceEndpoint(System.ServiceModel.Description.ServiceEndpoint endpoint);

Parameters

endpoint
ServiceEndpoint

The service endpoint.

Exceptions

Endpoint is null.

The host is not in a Created or an Opening state or there is no ServiceDescription for the hosted service.

The Address, Binding, or Contract property is null.

Remarks

When using the method, the service host does a "by-configuration-name" validation on the contract description. In other words, the host verifies that ConfigurationName exists in the list of configuration names of the service contracts implemented by the service. If the validation passes, the description in the ServiceEndpoint is used as it is, even if the ContractDescription reflected from the service is different.

As an example, assume that the description in the ServiceEndpoint and the contract description reflected from the service have the same name, but different operation behaviors. The implication of only "by-configuration-name" validation is that there is no validation that the behaviors are the same and there are one updates to one description because of another description.

If the address is a relative URI, one of the base addresses of the ServiceHost (depending on the binding protocol) is used as the endpoint's base address.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

AddServiceEndpoint(String, Binding, String)

Adds a service endpoint to the hosted service with a specified contract, binding, and endpoint address.

C#
public System.ServiceModel.Description.ServiceEndpoint AddServiceEndpoint(string implementedContract, System.ServiceModel.Channels.Binding binding, string address);

Parameters

implementedContract
String

The contract implemented by the endpoint.

binding
Binding

The Binding for the endpoint added.

address
String

The address for the endpoint added. This can be an absolute or relative URI. If it is a relative URI, one of the base address of the ServiceHost (depending on the binding protocol) is used as the endpoint's base address.

Returns

The ServiceEndpoint added to the hosted service.

Exceptions

implementedContract or binding or address or is null.

The host is not in a Created or an Opening state or there is no ServiceDescription for the hosted service and so an endpoint cannot be added or the binding lacks a transport of binding scheme.

Examples

C#
  NetTcpBinding portsharingBinding = new NetTcpBinding();
  hostDefault.AddServiceEndpoint(
typeof(CalculatorService),
portsharingBinding,
"net.tcp://localhost/MyService");

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

AddServiceEndpoint(String, Binding, Uri)

Adds a service endpoint to the hosted service with a specified contract, binding, and a URI that contains the endpoint address.

C#
public System.ServiceModel.Description.ServiceEndpoint AddServiceEndpoint(string implementedContract, System.ServiceModel.Channels.Binding binding, Uri address);

Parameters

implementedContract
String

The contract implemented by the endpoint.

binding
Binding

The Binding for the endpoint added.

address
Uri

The Uri that contains the address for the endpoint added. This can be an absolute or relative URI. If it is a relative URI, one of the base address of the ServiceHost (depending on the binding protocol) is used as the endpoint's base address.

Returns

The ServiceEndpoint added to the hosted service.

Exceptions

implementedContract or binding or address or is null.

The host is not in a Created or an Opening state or there is no ServiceDescription for the hosted service and so an endpoint cannot be added.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

AddServiceEndpoint(String, Binding, String, Uri)

Adds a service endpoint to the hosted service with a specified contract, binding, endpoint address and URI that contains the address at which it listens.

C#
public System.ServiceModel.Description.ServiceEndpoint AddServiceEndpoint(string implementedContract, System.ServiceModel.Channels.Binding binding, string address, Uri listenUri);

Parameters

implementedContract
String

The contract implemented by the endpoint.

binding
Binding

The Binding for the endpoint added.

address
String

The address for the endpoint added. This address can be an absolute or relative URI. If it is a relative URI, one of the base address of the ServiceHost (depending on the binding protocol) is used as the endpoint's base address.

listenUri
Uri

The Uri that contains the address which the endpoint listens to for incoming messages. This URI can be relative or absolute.

Returns

The ServiceEndpoint added to the hosted service.

Exceptions

implementedContract or binding or address or is null.

The host is not in a Created or an Opening state or there is no ServiceDescription for the hosted service and so an endpoint cannot be added.

Remarks

If the address is a relative URI, one of the base addresses of the ServiceHost (depending on the binding protocol) is used as the endpoint's base address.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

AddServiceEndpoint(String, Binding, Uri, Uri)

Adds a service endpoint to the hosted service with the specified contract, binding, and URIs that contain the endpoint and listening addresses.

C#
public System.ServiceModel.Description.ServiceEndpoint AddServiceEndpoint(string implementedContract, System.ServiceModel.Channels.Binding binding, Uri address, Uri listenUri);

Parameters

implementedContract
String

The contract implemented by the endpoint.

binding
Binding

The Binding for the endpoint added.

address
Uri

The Uri that contains the address for the endpoint added. If it is a relative URI, one of the base address of the ServiceHost (depending on the binding protocol) is used as the endpoint's base address.

listenUri
Uri

The Uri that contains the address at which the endpoint listens for incoming messages.

Returns

The ServiceEndpoint added to the hosted service. This URI can be absolute or relative.

Exceptions

implementedContract or binding or address or is null.

The host is not in a Created or an Opening state or there is no ServiceDescription for the hosted service and so an endpoint cannot be added.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1