Skip to content

Commit adfe821

Browse files
committed
Merge branch 'develop'
2 parents c0605eb + ba732af commit adfe821

17 files changed

+120
-701
lines changed

.semver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
:major: 1
33
:minor: 2
4-
:patch: 1
4+
:patch: 2
55
:special: ''

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ Installation
99

1010
NuGet> Install-Package WcfClientProxyGenerator
1111

12+
Usage
13+
-----
14+
To create a proxy, use the `WcfClientProxy.Create<TServiceInterface>()` method. There are multiple overloads that can be used to setup and configure the proxy.
15+
16+
#### WcfClientProxy.Create\<TServiceInterface\>()
17+
Calling create without passing any configuration in will configure the proxy using the `endpoint` section in your config where the `contract` attribute matches `TServiceInterface`. If more than one `endpoint` section exists, an `InvalidOperationException` is thrown. The alternate overloads must be used to select the appropriate endpoint configuration.
18+
19+
#### WcfClientProxy.Create\<TServiceInterface\>(string endpointConfigurationName)
20+
This is a shortcut to using the overload that accepts an `Action<IRetryingProxyConfigurator>`. It's the same as calling `WcfClientProxy.Create<TServiceInterface>(c => c.SetEndpoint(endpointConfigurationName))`.
21+
22+
#### WcfClientProxy.Create\<TServiceInterface\>(Action\<IRetryingProxyConfigurator\> config)
23+
Exposes the full configuration available. See the [Configuration](#configuration) section of the documentation.
24+
1225
Configuration
1326
-------------
1427
When calling the `WcfClientProxy.Create<TServiceInterface>()` method, a configuration Action is used to setup the proxy. The following configuration options are available at the proxy creation time:
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
33
<system.serviceModel>
4-
<client>
5-
<endpoint name="WcfClientProxyGenerator.Tests.Infrastructure.ITestService"
6-
address="http://localhost"
7-
binding="wsHttpBinding"
8-
contract="WcfClientProxyGenerator.Tests.Infrastructure.ITestService"/>
9-
4+
<client>
105
<endpoint name="ITestService"
116
address="http://localhost:23456/TestService"
127
binding="wsHttpBinding"
@@ -16,6 +11,11 @@
1611
address="http://localhost:23456/TestService2"
1712
binding="wsHttpBinding"
1813
contract="WcfClientProxyGenerator.Tests.Infrastructure.ITestService"/>
14+
15+
<endpoint name="ITestServiceSingleEndpointConfig"
16+
address="http://localhost:23456/TestService2"
17+
binding="wsHttpBinding"
18+
contract="WcfClientProxyGenerator.Tests.Infrastructure.ITestServiceSingleEndpointConfig"/>
1919
</client>
2020
</system.serviceModel>
2121
</configuration>

source/WcfClientProxyGenerator.Tests/DefaultProxyConfiguratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void SetEndpoint_IsCalledWith_FullNamespaceOfServiceInterface()
2020
DefaultProxyConfigurator.Configure<ITestService>(mockProxy.Object);
2121

2222
mockProxy.Verify(
23-
m => m.SetEndpoint(typeof(ITestService).FullName),
23+
m => m.UseDefaultEndpoint(),
2424
Times.Once());
2525
}
2626
}

source/WcfClientProxyGenerator.Tests/Infrastructure/IChildService.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.ServiceModel;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using NUnit.Framework;
1+
using System.ServiceModel;
82

93
namespace WcfClientProxyGenerator.Tests.Infrastructure
104
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.ServiceModel;
2+
3+
namespace WcfClientProxyGenerator.Tests.Infrastructure
4+
{
5+
[ServiceContract]
6+
public interface ITestServiceSingleEndpointConfig
7+
{
8+
[OperationContract]
9+
string TestMethod(string input);
10+
}
11+
}

source/WcfClientProxyGenerator.Tests/ProxyTests.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ namespace WcfClientProxyGenerator.Tests
1313
public class ProxyTests
1414
{
1515
[Test]
16-
[Description("Asserts that when no conguration is given in the Create proxy call, the endpoint with the full namespace of the service interface will be used")]
17-
public void CreatingProxy_WithNoConfigurator_GetsDefaultClientConfiguration()
16+
[Description("Asserts that when no conguration is given in the Create proxy call, the endpoint config that matches the contract will be used")]
17+
public void CreatingProxy_WithNoConfigurator_AndSingleEndpointConfig_GetsDefaultClientConfiguration()
1818
{
19-
WcfClientProxy.Create<ITestService>();
19+
WcfClientProxy.Create<ITestServiceSingleEndpointConfig>();
20+
}
21+
22+
[Test]
23+
[Description("Asserts that when no conguration is given in the Create proxy call, and multiple endpoint configs for the contract exist, an exception is thrown")]
24+
public void CreatingProxy_WithNoConfigurator_AndMultipleEndpointConfigs_ThrowsException()
25+
{
26+
Assert.That(
27+
() => WcfClientProxy.Create<ITestService>(),
28+
Throws.TypeOf<InvalidOperationException>());
2029
}
2130

2231
[Test]
@@ -27,6 +36,20 @@ public void CreatingProxy_WithNoConfigurator_AndNoDefaultConfiguration_ThrowsExc
2736
Throws.TypeOf<InvalidOperationException>());
2837
}
2938

39+
[Test]
40+
public void CreatingProxy_WithEndpointConfigurationName_ThatExists_CreatesProxy()
41+
{
42+
WcfClientProxy.Create<ITestService>("ITestService2");
43+
}
44+
45+
[Test]
46+
public void CreatingProxy_WithEndpointConfigurationName_ThatDoesNotExist_ThrowsException()
47+
{
48+
Assert.That(
49+
() => WcfClientProxy.Create<ITestService>("DoesNotExist"),
50+
Throws.TypeOf<InvalidOperationException>());
51+
}
52+
3053
[Test]
3154
public void Proxy_ReturnsExpectedValue_WhenCallingService()
3255
{

source/WcfClientProxyGenerator.Tests/WcfClientProxyGenerator.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<Compile Include="Infrastructure\ChildServiceImpl.cs" />
6666
<Compile Include="Infrastructure\IChildService.cs" />
6767
<Compile Include="Infrastructure\ITestService2.cs" />
68+
<Compile Include="Infrastructure\ITestServiceSingleEndpointConfig.cs" />
6869
<Compile Include="Infrastructure\TestService2Impl.cs" />
6970
<Compile Include="DelayPolicyTests.cs" />
7071
<Compile Include="ProxyTests.cs" />

source/WcfClientProxyGenerator/ChannelFactoryProvider.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,42 @@ internal static class ChannelFactoryProvider
1111
private static readonly ConcurrentDictionary<string, Lazy<object>> ChannelFactoryCache
1212
= new ConcurrentDictionary<string, Lazy<object>>();
1313

14+
public static ChannelFactory<TServiceInterface> GetChannelFactory<TServiceInterface>()
15+
where TServiceInterface : class
16+
{
17+
string cacheKey = GetCacheKey<TServiceInterface>();
18+
return GetChannelFactory(cacheKey, () => new ChannelFactory<TServiceInterface>("*"));
19+
}
20+
1421
public static ChannelFactory<TServiceInterface> GetChannelFactory<TServiceInterface>(string endpointConfigurationName)
1522
where TServiceInterface : class
1623
{
1724
string cacheKey = GetCacheKey<TServiceInterface>(endpointConfigurationName);
18-
var channelFactory = ChannelFactoryCache.GetOrAddSafe(
19-
cacheKey,
20-
_ => new ChannelFactory<TServiceInterface>(endpointConfigurationName));
21-
22-
return channelFactory as ChannelFactory<TServiceInterface>;
25+
return GetChannelFactory(cacheKey, () => new ChannelFactory<TServiceInterface>(endpointConfigurationName));
2326
}
2427

2528
public static ChannelFactory<TServiceInterface> GetChannelFactory<TServiceInterface>(Binding binding, EndpointAddress endpointAddress)
2629
where TServiceInterface : class
2730
{
2831
string cacheKey = GetCacheKey<TServiceInterface>(binding, endpointAddress);
32+
return GetChannelFactory(cacheKey, () => new ChannelFactory<TServiceInterface>(binding, endpointAddress));
33+
}
34+
35+
private static ChannelFactory<TServiceInterface> GetChannelFactory<TServiceInterface>(string cacheKey, Func<ChannelFactory<TServiceInterface>> factory)
36+
where TServiceInterface : class
37+
{
2938
var channelFactory = ChannelFactoryCache.GetOrAddSafe(
3039
cacheKey,
31-
_ => new ChannelFactory<TServiceInterface>(binding, endpointAddress));
40+
_ => factory());
3241

3342
return channelFactory as ChannelFactory<TServiceInterface>;
3443
}
3544

45+
private static string GetCacheKey<TServiceInterface>()
46+
{
47+
return string.Format("type:{0}", typeof(TServiceInterface).FullName);
48+
}
49+
3650
private static string GetCacheKey<TServiceInterface>(string endpointConfigurationName)
3751
{
3852
return string.Format("type:{0};config:{1}",

source/WcfClientProxyGenerator/DefaultProxyConfigurator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ internal static class DefaultProxyConfigurator
77
{
88
public static void Configure<TServiceInterface>(IRetryingProxyConfigurator proxy)
99
{
10-
proxy.SetEndpoint(typeof(TServiceInterface).FullName);
10+
proxy.UseDefaultEndpoint();
1111
}
1212

1313
public static readonly Func<LinearBackoffDelayPolicy> DefaultDelayPolicyFactory

0 commit comments

Comments
 (0)