public object Call(ServiceDetail svc, List <object> payLoads)
        {
            //Import WSDL
            WsdlImporter imptr = ImportWSDL(svc.WSDLUri);
            //Extract Service and Data Contract Descriptions
            Collection <ContractDescription> svcCtrDesc = imptr.ImportAllContracts();
            //Compile the description to assembly
            var assembly = GetAssembly(svcCtrDesc);

            if (assembly == null)
            {
                return(null);
            }
            //Extract all end points available on the WSDL
            IDictionary <string, IEnumerable <ServiceEndpoint> > allEP = GetEndPointsOfEachServiceContract(imptr, svcCtrDesc);
            IEnumerable <ServiceEndpoint> currentSvcEP;

            if (allEP.TryGetValue(svc.ContractName, out currentSvcEP))
            {
                //Find the endpoint of the service to which the proxy needs to contact
                var svcEP = currentSvcEP.First(x => x.ListenUri.AbsoluteUri == svc.ServiceUri.AbsoluteUri);
                //Generate proxy
                var proxy = GetProxy(svc.ContractName, svcEP, assembly);
                //Deserialize each payload argument to object
                List <object> pls = new List <object>();
                foreach (var pl in payLoads)
                {
                    object clrObj = null;
                    try
                    {
                        clrObj = Deserialize(pl.ToString(), assembly);
                    }
                    catch
                    {
                        clrObj = pl;
                    }
                    pls.Add(clrObj);
                }
                //Find opration contract on the proxy and invoke
                return(proxy.GetType().GetMethod(svc.MethodName).Invoke(proxy, pls.ToArray()));
            }
            return(null);
        }
        public void TestMethod1()
        {
            // Arrange
            var target        = new GenericService();
            var serviceDetail = new ServiceDetail
            {
                WSDLUri      = new Uri("http://localhost:13152/Service1.svc?singleWsdl"),
                ServiceUri   = new Uri("http://localhost:13152/Service1.svc"),
                ContractName = "IService1",
                MethodName   = "GetData"
            };
            var arguments = new List <object> {
                5
            };
            // Act
            var result = target.Call(serviceDetail, arguments);

            // Assert
            Assert.AreEqual("You entered: 5", result);
        }
Ejemplo n.º 3
0
        public void Process_MessageAction_ServiceDetails_CallsServiceDetails()
        {
            var dt = DateTime.Now;

            var details = new ServiceDetail
            {
                Cpus        = 4,
                ConnectTime = dt,
                IsConnected = true,
                License     = "1234abcde",
                Name        = "service1"
            };

            var m = new Message
            {
                Id     = guid,
                Action = MessageAction.ServiceDetails
            };

            var message = JsonConvert.SerializeObject(m);
            Mock <IPviApplication> pviApplicationMock = new Mock <IPviApplication>();

            pviApplicationMock.Setup(p => p.ServiceDetails()).Returns(details);
            var proc     = new MessageProcessor(pviApplicationMock.Object);
            var response = proc.Process(message);

            var result = JsonConvert.DeserializeObject <ServiceDetail>(response.Message);

            Assert.NotNull(result);
            Assert.IsType <ServiceDetail>(result);
            Assert.Equal(result.Cpus, details.Cpus);
            Assert.Equal(result.ConnectTime, details.ConnectTime);
            Assert.Equal(result.IsConnected, details.IsConnected);
            Assert.Equal(result.License, details.License);
            Assert.Equal(result.Name, details.Name);
        }