diff --git a/source/WcfClientProxyGenerator.Tests/ProxyTests.cs b/source/WcfClientProxyGenerator.Tests/ProxyTests.cs index 29a5f88..8fa8d7c 100644 --- a/source/WcfClientProxyGenerator.Tests/ProxyTests.cs +++ b/source/WcfClientProxyGenerator.Tests/ProxyTests.cs @@ -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(); + + service + .FaultMethod(Arg.Any()) + .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(); + + service + .KnownTypeMethod(Arg.Any()) + .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() { diff --git a/source/WcfClientProxyGenerator/DynamicProxyTypeGenerator.cs b/source/WcfClientProxyGenerator/DynamicProxyTypeGenerator.cs index e3adbf3..d387ec4 100644 --- a/source/WcfClientProxyGenerator/DynamicProxyTypeGenerator.cs +++ b/source/WcfClientProxyGenerator/DynamicProxyTypeGenerator.cs @@ -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);