Skip to content

Commit

Permalink
Issue #22 - Restricting fault and known type attributes from being co…
Browse files Browse the repository at this point in the history
…pied to the async interface

These attributes are restricted from being placed on task based async methods as per `System.ServiceModel.Description.TypeLoader.VerifyConsistency`
  • Loading branch information
jweber committed May 11, 2016
1 parent e8b6dad commit cb20870
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
34 changes: 33 additions & 1 deletion source/WcfClientProxyGenerator.Tests/ProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,39 @@ public void CreatingProxy_TrailingSlashOnNamespace()

Assert.That(result, Is.EqualTo("hello"));
}


[Test, Description("Github issue #22")]
public async Task AsyncMethod_FromSyncMethodWithFaultContract_CanBeCalled()
{
var service = Substitute.For<ICustomAttributeService>();

service
.FaultMethod(Arg.Any<string>())
.Returns("hello");

var proxy = service.StartHostAndAsyncProxy();

var result = await proxy.CallAsync(m => m.FaultMethod(""));

Assert.That(result, Is.EqualTo("hello"));
}

[Test, Description("Github issue #22")]
public async Task AsyncMethod_FromSyncMethodWithKnownTypeAttribute_CanBeCalled()
{
var service = Substitute.For<ICustomAttributeService>();

service
.KnownTypeMethod(Arg.Any<string>())
.Returns("hello");

var proxy = service.StartHostAndAsyncProxy();

var result = await proxy.CallAsync(m => m.KnownTypeMethod(""));

Assert.That(result, Is.EqualTo("hello"));
}

[Test]
public void Proxy_ReturnsExpectedValue_WhenCallingService()
{
Expand Down
9 changes: 8 additions & 1 deletion source/WcfClientProxyGenerator/DynamicProxyTypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,16 @@ private static void GenerateAsyncTaskMethod(

methodBuilder.SetCustomAttribute(cloneOperationContractAttribute());

var restrictedAttributeTypes = new[]
{
typeof(OperationContractAttribute),
typeof(FaultContractAttribute),
typeof(ServiceKnownTypeAttribute)
};

var remainingCustomAttributes = methodInfo
.GetCustomAttributesData()
.Where(m => m.AttributeType != typeof(OperationContractAttribute));
.Where(m => !restrictedAttributeTypes.Contains(m.AttributeType));

foreach (var builder in CloneCustomAttributes(remainingCustomAttributes))
methodBuilder.SetCustomAttribute(builder);
Expand Down

0 comments on commit cb20870

Please sign in to comment.