Inheritance: FuelObject
        static void TestET_Endpoint()
        {
            ET_Client myclient = new ET_Client();

            Console.WriteLine("--- Testing Endpoint ---");

            Console.WriteLine("\n Retrieve All Endpoints");
            ET_Endpoint getEndpoint = new ET_Endpoint();
            getEndpoint.AuthStub = myclient;
            GetReturn grEndpoint = getEndpoint.Get();

            Console.WriteLine("Get Status: " + grEndpoint.Status.ToString());
            Console.WriteLine("Message: " + grEndpoint.Message.ToString());
            Console.WriteLine("Code: " + grEndpoint.Code.ToString());
            Console.WriteLine("Results Length: " + grEndpoint.Results.Length);
            Console.WriteLine("MoreResults: " + grEndpoint.MoreResults.ToString());

            Console.WriteLine("\n Retrieve Single Endpoint by Type");
            ET_Endpoint getSingleEndpoint = new ET_Endpoint();
            getSingleEndpoint.AuthStub = myclient;
            getSingleEndpoint.Type = "soap";
            GetReturn grSingleEndpoint = getSingleEndpoint.Get();

            Console.WriteLine("Get Status: " + grSingleEndpoint.Status.ToString());
            Console.WriteLine("Message: " + grSingleEndpoint.Message.ToString());
            Console.WriteLine("Code: " + grSingleEndpoint.Code.ToString());
            Console.WriteLine("Results Length: " + grSingleEndpoint.Results.Length);
            Console.WriteLine("MoreResults: " + grSingleEndpoint.MoreResults.ToString());

        }
Exemple #2
0
        //Constructor
        public ET_Client(NameValueCollection parameters = null)
        {
            //Get configuration file and set variables
            System.Xml.XPath.XPathDocument doc = new System.Xml.XPath.XPathDocument(@"FuelSDK_config.xml");
            foreach (System.Xml.XPath.XPathNavigator child in doc.CreateNavigator().Select("configuration"))
            {
                appSignature = child.SelectSingleNode("appSignature").Value.ToString().Trim();
                clientId = child.SelectSingleNode("clientId").Value.ToString().Trim();
                clientSecret = child.SelectSingleNode("clientSecret").Value.ToString().Trim();
                soapEndPoint = child.SelectSingleNode("soapEndPoint").Value.ToString().Trim();
            }         

            //If JWT URL Parameter Used
            if (parameters != null && parameters.AllKeys.Contains("jwt"))
            {
                string encodedJWT = parameters["jwt"].ToString().Trim();
                String decodedJWT = JsonWebToken.Decode(encodedJWT, appSignature);
                JObject parsedJWT = JObject.Parse(decodedJWT);
                authToken = parsedJWT["request"]["user"]["oauthToken"].Value<string>().Trim();
                authTokenExpiration = DateTime.Now.AddSeconds(int.Parse(parsedJWT["request"]["user"]["expiresIn"].Value<string>().Trim()));
                internalAuthToken = parsedJWT["request"]["user"]["internalOauthToken"].Value<string>().Trim();
                refreshKey = parsedJWT["request"]["user"]["refreshToken"].Value<string>().Trim();
            }          
            else
            {
                refreshToken();
            }

            // Find the appropriate endpoint for the acccount
            ET_Endpoint getSingleEndpoint = new ET_Endpoint();
            getSingleEndpoint.AuthStub = this;
            getSingleEndpoint.Type = "soap";
            GetReturn grSingleEndpoint = getSingleEndpoint.Get();

            if (grSingleEndpoint.Status && grSingleEndpoint.Results.Length == 1){
                soapEndPoint =  ((ET_Endpoint)grSingleEndpoint.Results[0]).URL;
            } else {
                throw new Exception("Unable to determine stack using /platform/v1/endpoints: " + grSingleEndpoint.Message);
            }

            //Create the SOAP binding for call with Oauth.
            BasicHttpBinding binding = new BasicHttpBinding();
            binding.Name = "UserNameSoapBinding";
            binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
            binding.MaxReceivedMessageSize = 2147483647;
            soapclient = new SoapClient(binding, new EndpointAddress(new Uri(soapEndPoint)));
            soapclient.ClientCredentials.UserName.UserName = "******";
            soapclient.ClientCredentials.UserName.Password = "******";

        }