question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WCF service interception is not supported

See original GitHub issue

WCF service won’t be hosted if it has an interceptor. Using: Windsor 3.4.0, .Net 4.6.1.

Here is how WCF service is created:

[ServiceContract]
public interface IEmployeeService
{
  [OperationContract, WebInvoke(Method = "GET", UriTemplate = "/get/{value}")]
  string GetData(string value);
}

public class EmployeeService : IEmployeeService
{
  public string GetData(string value)
  {
    return $"You entered: {value}";
  }
}

public interface IWcfInterceptor: IInterceptor { }

public class WcfInterceptor : IWcfInterceptor
{
  // implementation goes here
}
// ...........
// 0. Create windsor container, add wcf facility;
// 1. Register the interceptor component;
// 2. Register the WCF service;
Component.For<IEmployeeService>()
  .ImplementedBy<EmployeeService>()
    .AsWcfService(new RestServiceModel()
      .AddBaseAddresses("http://localhost:30115/employee")
      .AddEndpoints(WcfEndpoint.ForContract<IEmployeeService>()
      .BoundTo(new WebHttpBinding())
      .At("rest"))
    )
    .AsWcfService(new DefaultServiceModel()
      .AddBaseAddresses("http://localhost:30115/employee")
      .AddEndpoints(WcfEndpoint.ForContract<IEmployeeService>()
      .BoundTo(new WSHttpBinding())
      .At("soap")).PublishMetadata(o => o.EnableHttpGet())
    )
    .Interceptors<IWcfInterceptor>() // this is not supported

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
ghostcommented, Jul 2, 2017

Hi,

I changed your test to be the following:


[Test]
public void CanCreateServiceHostAndOpenServiceHostWithInterceptor()
{
	using (new WindsorContainer()
		.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
		.Register(
		Component.For<ServiceInterceptor>(), // <-- Removed interface as service type for interceptor
		Component.For<IOperations>()
			.ImplementedBy<Operations>()
			.DependsOn(new { number = 42 })
			.AsWcfService(new DefaultServiceModel().AddEndpoints(
				WcfEndpoint.BoundTo(new NetTcpBinding { PortSharingEnabled = true })
					.At("net.tcp://localhost/Operations"))
			)
			.Interceptors<ServiceInterceptor>()
		))
	{
		var client = ChannelFactory<IOperations>.CreateChannel(
new NetTcpBinding { PortSharingEnabled = true }, new EndpointAddress("net.tcp://localhost/Operations"));
		Assert.AreEqual(42, client.GetValueFromConstructor());
	}
}    

public class ServiceInterceptor : IInterceptor
{
	public void Intercept(IInvocation invocation)
	{
		invocation.Proceed(); // <-- Made sure the invocation proceeds
	}
}


*** Edited ***

If you are interested in getting the underlying values back you have to call invocation.proceed. Also Windsor does not really care that interceptors are registered with IInvocation as a service type, this is more a Castle Core dynamic proxy thing.

Hope this helps! 😃

0reactions
johnskycommented, Jul 3, 2017

@fir3pho3nixx Thank you for the help! It was unexpected to me that Winsor does not resolve a component by service type as interceptor when ComponentRegistration.Interceptors<TService>() is called. =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I intercept all calls to methods in a WCF .svc ...
Ive got a WCF service which has multiple web methods in it. I want to be able to intercept the request on all...
Read more >
DynamicProxy interception does not work for WCF clients
Register a WCF client according to the Wiki page WcfIntegration and add AOP interception according to the Wiki DynamicProxy2 I would expect for ......
Read more >
WCF services and ASP.NET
This topic discusses hosting Windows Communication Foundation (WCF) services side-by-side with ASP.NET and hosting them in ASP.
Read more >
Print
Enrolling in WCF's SMS Program is not a condition of purchase or service. As one of the WCF SMS Programs, WCF Insurance offers...
Read more >
WCF Essentials-A Developer's Primer
Without the ServiceContractAttribute, the interface is not visible to WCF clients, in line with the service-oriented tenet that service boundaries are explicit.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found