dotnet / dotnet/wcf

EndpointDispatcher cannot be used on IEndpointBehavior because it is missing all of the fields.

Open
#5,330 1 comment 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

**Describe the bug**
Using `System.ServiceModel.Primitives` 6.1.0 with a net6.0 project I followed the instructions for creating a Message Inspector on a Service (not a client).

I get this build error. The `EndpointDispatcher `appears to have no publicly accesible properties or methods in intellisense and during the build.

```
CS1061 'EndpointDispatcher' does not contain a definition for 'DispatchRuntime' and no accessible extension method 'DispatchRuntime' accepting a first argument of type 'EndpointDispatcher' could be found (are you missing a using directive or an assembly reference?)
```

The documentation indicates this is how to add a Message Inspector for a service using `ApplyDispatchBehavior`:
[https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/message-inspectors](https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/message-inspectors)

```c#
public class SchemaValidationBehavior : IEndpointBehavior
{
XmlSchemaSet schemaSet;
bool validateRequest;
bool validateReply;

public SchemaValidationBehavior(XmlSchemaSet schemaSet, bool
inspectRequest, bool inspectReply)
{
this.schemaSet = schemaSet;
this.validateReply = inspectReply;
this.validateRequest = inspectRequest;
}
#region IEndpointBehavior Members

public void AddBindingParameters(ServiceEndpoint endpoint,
System.ServiceModel.Channels.BindingParameterCollection
bindingParameters)
{
}

public void ApplyClientBehavior(ServiceEndpoint endpoint,
System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
SchemaValidationMessageInspector inspector =
new SchemaValidationMessageInspector(schemaSet,
validateRequest, validateReply, true);
clientRuntime.MessageInspectors.Add(inspector);
}

public void ApplyDispatchBehavior(ServiceEndpoint endpoint,
System.ServiceModel.Dispatcher.EndpointDispatcher
endpointDispatcher)
{
SchemaValidationMessageInspector inspector =
new SchemaValidationMessageInspector(schemaSet,
validateRequest, validateReply, false);
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
}

public void Validate(ServiceEndpoint endpoint)
{
}

#endregion
}
````

**To Reproduce**
Use System.ServiceModel.Primitives 6.1.0 and try to create the message inspector behavior in the documentation.

**Expected behavior**
I should be able to add a Message Inspector to the service.

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.