private bool Discover(ServiceHelloWCFClientProxy proxy)
        {
            DpwsServiceTypes typeProbes = new DpwsServiceTypes();

            typeProbes.Add(new DpwsServiceType("IServiceHelloWCF", "http://localhost/ServiceHelloWCF"));

            DpwsServiceDescriptions descs = proxy.DiscoveryClient.Probe(typeProbes, 1, 20000);

            if (descs.Count > 0)
            {
                proxy.EndpointAddress = descs[0].XAddrs[0];
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public void Run()
        {
            Uri remoteEp = new Uri("http://localhost:8084/ServiceHelloWCF.svc");
            WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig(remoteEp));

            ProtocolVersion ver = new ProtocolVersion11();

            // To enable WSDiscoveryApril2005 and Soap12WSAddressingAugust2004
            //ProtocolVersion ver = new ProtocolVersion10();

            /// ProtocolVersion11 can be used if the corresponding WCF desktop server application
            /// WcfServer uses wsHttpBinding instead of the custom binding "Soap11AddressingBinding"
            m_clientProxy = new ServiceHelloWCFClientProxy(binding, ver);

            m_clientProxy.IgnoreRequestFromThisIP = false;

            if (!Discover(m_clientProxy))
            {
                Debug.Print("Discovery failed, trying direct address");
            }

            HelloWCF req = new HelloWCF();

            req.name = "World";

            try
            {
                HelloWCFResponse resp = m_clientProxy.HelloWCF(req);

                Debug.Print("\n\n*****************");
                Debug.Print(resp.HelloWCFResult);
                Debug.Print("*****************\n\n");
            }
            catch (WsFaultException ex)
            {
                Debug.Print("DPWS Fault: " + ex.Message);
            }
            finally
            {
                m_clientProxy.Dispose();
            }
        }
        public void Run()
        {
            Uri remoteEp = new Uri("http://localhost:8001/ServiceHelloWCF");
            WS2007HttpBinding binding = new WS2007HttpBinding(new HttpTransportBindingConfig(remoteEp));

            /// ProtocolVersion11 can be used if the corresponding WCF desktop server application
            /// WcfServer uses wsHttpBinding instead of the custom binding "Soap11AddressingBinding"
            m_clientProxy = new ServiceHelloWCFClientProxy(binding, new ProtocolVersion11());

            m_clientProxy.IgnoreRequestFromThisIP = false;

            if (!Discover(m_clientProxy))
            {
                Debug.Print("Discovery failed, trying direct address");
                m_clientProxy.EndpointAddress = "http://localhost:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D";
            }

            HelloWCF req = new HelloWCF();

            req.name = "World";

            try
            {
                HelloWCFResponse resp = m_clientProxy.HelloWCF(req);

                Debug.Print("\n\n*****************");
                Debug.Print(resp.HelloWCFResult);
                Debug.Print("*****************\n\n");
            }
            catch (WsFaultException ex)
            {
                Debug.Print("DPWS Fault: " + ex.Message);
            }

            m_clientProxy.Dispose();
        }