public string InvokeProxyMethod(TestCase test)
{ string ret = "Failed to call test case...";
// determine the contract type
ServiceClientContract contract = _contracts[test.ContractName];
ClientEndpoint endpoint = contract.Endpoints[test.EndpointName];
Type contractType = Assemblies[test.Assembly].GetType(endpoint.Contract);
// create the factory to generate the channel
Type factoryType = typeof(ContractChannelFactory<>).MakeGenericType(contractType);
Object factory = Activator.CreateInstance(factoryType, new object[] {test.EndpointName, contract.FileName});
// create the channel
IUntypedChannel channel = (IUntypedChannel)factoryType.InvokeMember("CreateUntypedChannel", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, factory, new object[] { test.URL });
// determine the action
MemberInfo s = contractType.GetMethod(test.Method);
object[] attributes = s.GetCustomAttributes(typeof(OperationContractAttribute), true);
if (attributes.Length == 1)
{ using (StringReader sr = new StringReader(test.Input))
{ // build an untyped message with the same message version, input and action
XmlReader xr = XmlTextReader.Create(sr);
OperationContractAttribute attribute = (OperationContractAttribute)attributes[0];
MessageVersion version = (MessageVersion)factoryType.InvokeMember("GetMessageVersion", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, factory, new object[] { }); Message request = Message.CreateMessage(version, attribute.Action, xr);
// call the service
Message response = channel.Post(request);
ret = response.ToString();
xr.Close();
sr.Close();
}
}
return ret;
}