コード例 #1
0
 public SalesForceProperty(MCser.SoapClient _soapClient, Boolean _isTest, String _AuthToken, String _ServiceURL)
 {
     SoapClient = _soapClient;
     isTest     = _isTest;
     AuthToken  = _AuthToken;
     ServiceURL = _ServiceURL;
 }
コード例 #2
0
        protected override void Execute(NativeActivityContext context)
        {
            RestSharp.RestClient client     = new RestSharp.RestClient();
            MCser.SoapClient     soapClient = null;

            String ExistAuthToken  = "" + ExistingAuth.Get(context);
            String ExistServiceURL = "" + ExistingServ.Get(context);

            if (ExistAuthToken.Trim().Length > 1)
            {
                RespAuthToken  = ExistAuthToken.Trim();
                RespServiceURL = ExistServiceURL.Trim();
            }
            else
            {
                String  sfdcConsumerkey    = "";
                String  sfdcConsumerSecret = "";
                String  sfdcServiceURL     = "";
                String  sfdcUserName       = "";
                String  sfdcPassword       = "";
                Boolean EnvType            = (EnvironmentType == Type_of_Environment.Design_and_Test) ? true : false;
                if (EnvType)
                {
                    sfdcConsumerkey    = ConsumerKey.Get(context);
                    sfdcConsumerSecret = ConsumerSecret.Get(context);
                    sfdcServiceURL     = ServiceURL.Get(context);
                    sfdcUserName       = UserName.Get(context);
                    sfdcPassword       = Password.Get(context);
                }
                else
                {
                    sfdcConsumerkey    = ConsumerKeyProd.Get(context);
                    sfdcConsumerSecret = SecureStringToString(ConsumerSecretProd.Get(context));
                    sfdcServiceURL     = "" + SecureStringToString(ServiceURLProd.Get(context));
                    sfdcUserName       = UserNameProd.Get(context);
                    sfdcPassword       = SecureStringToString(PasswordProd.Get(context));
                }

                try
                {
                    client.BaseUrl = new Uri("https://auth.exacttargetapis.com/v1/requestToken");

                    var request2 = new RestRequest(Method.POST);
                    request2.RequestFormat = DataFormat.Json;
                    request2.AddParameter("clientId", sfdcConsumerkey);
                    request2.AddParameter("clientSecret", sfdcConsumerSecret);

                    JObject jsonObj = JObject.Parse(client.Post(request2).Content);
                    RespAuthToken = (String)jsonObj["accessToken"];
                    String ErrorType = "";
                    ErrorType = (String)jsonObj["error"];
                    String ErrorMsg = "";
                    ErrorMsg = (String)jsonObj["error_description"];


                    if ((RespAuthToken != null && RespAuthToken != "") && ErrorMsg == null)
                    {
                        BasicHttpsBinding binding = new BasicHttpsBinding();
                        binding.Name                   = "MyServicesSoap";
                        binding.CloseTimeout           = TimeSpan.FromMinutes(1);
                        binding.OpenTimeout            = TimeSpan.FromMinutes(1);
                        binding.ReceiveTimeout         = TimeSpan.FromMinutes(60);
                        binding.SendTimeout            = TimeSpan.FromMinutes(1);
                        binding.AllowCookies           = false;
                        binding.BypassProxyOnLocal     = false;
                        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                        binding.MaxBufferSize          = 20000000;
                        binding.MaxBufferPoolSize      = 20000000;
                        binding.MaxReceivedMessageSize = 20000000;
                        binding.MessageEncoding        = WSMessageEncoding.Text;
                        binding.TextEncoding           = System.Text.Encoding.UTF8;
                        binding.TransferMode           = TransferMode.Buffered;
                        binding.UseDefaultWebProxy     = true;

                        binding.ReaderQuotas.MaxDepth = 32;
                        binding.ReaderQuotas.MaxStringContentLength = 8192;
                        binding.ReaderQuotas.MaxArrayLength         = 16384;
                        binding.ReaderQuotas.MaxBytesPerRead        = 4096;
                        binding.ReaderQuotas.MaxNameTableCharCount  = 16384;

                        binding.Security.Mode = BasicHttpsSecurityMode.Transport;
                        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                        binding.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.None;
                        binding.Security.Transport.Realm = "";
                        binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
                        binding.Security.Message.AlgorithmSuite       = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;


                        String          endpointStr = "https://webservice.s10.exacttarget.com/Service.asmx";
                        EndpointAddress endpoint    = new EndpointAddress(endpointStr);
                        soapClient = new MCser.SoapClient(binding, endpoint);
                        soapClient.ClientCredentials.UserName.UserName = sfdcUserName;
                        soapClient.ClientCredentials.UserName.Password = sfdcPassword;
                        soapClient.Endpoint.EndpointBehaviors.Add(new FuelOAuthHeaderBehavior(RespAuthToken));
                        RespServiceURL = sfdcServiceURL;
                    }
                    else if (RespAuthToken == null && (ErrorMsg != "" && ErrorMsg != null))
                    {
                        RespAuthToken  = "Error Type: " + ErrorType;
                        RespServiceURL = "Error: " + ErrorMsg;
                    }
                }
                catch (Exception ex)
                {
                    RespAuthToken  = "Error Type: " + ex.ToString();
                    RespServiceURL = "Error: " + ex.ToString();
                }
            }

            var salesForceProperty = new SalesForceProperty(soapClient, true, RespAuthToken, RespServiceURL);

            if (Body != null)
            {
                context.ScheduleAction <SalesForceProperty>(Body, salesForceProperty, OnCompleted, OnFaulted);
            }
        }