Hi Craig, i have created a test which outlines my problem, I have used
the existing WcfServiceFixture as a reference.
I was expecting an exception to be thrown by the
NetDataContractSerializerOperationBehavior.
[TestFixture]
public class WcfOperationBehaviorTestFixture
{
private ISimpleService _client;
private IWindsorContainer _container;
[SetUp]
public void TestInitialize()
{
_container = new WindsorContainer().AddFacility<WcfFacility>(f
=> f.CloseTimeout = TimeSpan.Zero)
.Register(
Component.For<NetDataContractFormatBehavior>(),
Component.For<ISimpleService>
().ImplementedBy<SimpleService>()
.ActAs(new DefaultServiceModel().AddEndpoints(
WcfEndpoint.BoundTo(new NetTcpBinding
{ PortSharingEnabled = true })
.At("net.tcp://localhost/ReturnService")
)
)
);
_client = ChannelFactory<ISimpleService>.CreateChannel(
new NetTcpBinding { PortSharingEnabled = true },
new EndpointAddress("net.tcp://localhost/ReturnService")
);
}
[TearDown]
public void TestCleanup()
{
_container.Dispose();
}
[Test]
[ExpectedException(typeof(NotImplementedException))]
public void ThrowExceptionDuringCreateSerializer()
{
var name = Guid.NewGuid().ToString();
var foo = _client.Fetch(name);
}
}
public class NetDataContractFormatBehavior : IOperationBehavior
{
#region IOperationBehavior Members
public void AddBindingParameters(OperationDescription description,
BindingParameterCollection parameters)
{
}
public void ApplyClientBehavior(OperationDescription description,
ClientOperation proxy)
{
ReplaceDataContractSerializerOperationBehavior(description);
}
public void ApplyDispatchBehavior(OperationDescription
description, DispatchOperation dispatch)
{
ReplaceDataContractSerializerOperationBehavior(description);
}
public void Validate(OperationDescription description)
{
}
#endregion
public static void ReplaceDataContractSerializerOperationBehavior
(OperationDescription description)
{
var behavior =
description.Behaviors.Find<DataContractSerializerOperationBehavior>();
if (behavior != null)
{
description.Behaviors.Remove(behavior);
description.Behaviors.Add(new
NetDataContractSerializerOperationBehavior(description));
}
}
public class NetDataContractSerializerOperationBehavior :
DataContractSerializerOperationBehavior
{
public NetDataContractSerializerOperationBehavior
(OperationDescription operationDescription) : base
(operationDescription)
{
}
public override XmlObjectSerializer CreateSerializer(Type
type, string name, string ns, IList<Type> knownTypes)
{
throw new NotImplementedException();
}
public override XmlObjectSerializer CreateSerializer(Type
type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type>
knownTypes)
{
throw new NotImplementedException();
}
}
}
[ServiceContract]
public interface ISimpleService
{
[OperationContract]
Foo Fetch(string name);
[OperationContract]
string Save(Foo foo);
}
public class SimpleService : ISimpleService
{
public Foo Fetch(string name)
{
return new Foo {Name = name};
}
public string Save(Foo foo)
{
return foo.Name;
}
}
[DataContract]
public class Foo
{
[DataMember]
public string Name { get; set; }
}
--
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.