EagleML Web Service - Create the .NET WCF Solution

This page will walk you through creating the .NET WCF solution. 

Click the zip archive below to download the code described on this page.

To create the .NET WCF solution:

  1. Create a console .NET application.
  2. In the Solution Explorer tab, right click Service references and select Add Service Reference… in the context menu.

    Add Service Reference window will pop up.
  3. Type the server WSDL link into the Address Input field (%host%/EagleMLWebService20?wsdl) and fill the Namespace input field with an appropriate namespace (e.g. EagleMlWebReference ) for generated classes. and press Go.
  4. Once the Login form appears, type the username and password to access web service and press OK.

    A few seconds later, the available Web Services and available methods for them will be displayed.
  5. Select EagleMLWebService and press OK.
  6. In the Solution Explorer, find your EagleMlWebReference service in the Service References folder.
  7. Open the program.cs file and add workaround to the Main method to disable any errors with ssl certificates. Then create MakeEagleCall method and add it to the Main method, as follows:

    static void Main(string[] args)
            {
                //disable any errors with certificates
                System.Net.ServicePointManager.ServerCertificateValidationCallback =
                delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                        System.Security.Cryptography.X509Certificates.X509Chain chain,
                                        System.Net.Security.SslPolicyErrors sslPolicyErrors)
                {
                    return true; // **** Always accept
                };
                MakeEagleCall();
            }
     
    private static void MakeEagleCall()
            {
                //initial variables
                string url = "your end point url";
                string user = "****";
                string password = "****";
                       
                try
                {
                    BasicHttpBinding bbinding = new BasicHttpBinding();
                    //
                    Uri uri = new Uri(url);
                    if (uri.Scheme == "https")
                    {
                        bbinding.Security.Mode = BasicHttpSecurityMode.Transport;
                    }
                    else
                    {
                        bbinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                    }
                    bbinding.AllowCookies = false;
                    int mb = 1048576;
                    bbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
                    bbinding.MaxReceivedMessageSize = 50 * mb;
                    bbinding.MaxBufferSize = 50 * mb;
                    bbinding.MaxBufferPoolSize = 50 * mb;
                    bbinding.ReceiveTimeout = new TimeSpan(0, 15, 0);
                    bbinding.SendTimeout = new TimeSpan(0, 15, 0);
                    ICollection<BindingElement> bindingElements = bbinding.CreateBindingElements();
                    //workaround for incorrect contentType
                    HttpTransportBindingElement httpBindingElement = bindingElements.SingleOrDefault(p => p is HttpTransportBindingElement) as HttpTransportBindingElement;
                    CustomTextMessageBindingElement textBindingElement = new CustomTextMessageBindingElement();
                    bindingElements = new List<BindingElement>();
                    bindingElements.Add(textBindingElement);
                    bindingElements.Add(httpBindingElement);
                    CustomBinding binding = new CustomBinding(bindingElements);
                    binding.ReceiveTimeout = new TimeSpan(0, 15, 0);
                    binding.SendTimeout = new TimeSpan(0, 15, 0);
                    //set endpoint
                    EndpointAddress address = new EndpointAddress(url);
                    //create EagleMLPortTypeClient
                    using (eagleSvc.EagleMLPortTypeClient myClient = new eagleSvc.EagleMLPortTypeClient(binding, address))
                    {
                       
                        //set credentials
                        myClient.ClientCredentials.UserName.UserName = user;
                        myClient.ClientCredentials.UserName.Password = password;
                                           
                        try
                        {  
                            eagleSvc.WSTaskAcknowledgement ack1;
                            eagleSvc.WSTaskStatusResponse resExtract;
                            //async request
                            var runTaskRequest = GenerateRunTaskRequest();
                            ack1 = myClient.RunTaskRequest(runTaskRequest);
                            //async request with ftp
                            runTaskRequest = GenerateFTPRunTaskRequest();
                            ack1 = myClient.RunTaskRequest(runTaskRequest);
                            //sync request
                            runTaskRequest = GenerateSyncRunTaskRequest();
                            resExtract = myClient.RunTaskRequestSync(runTaskRequest);
                           
                            string extract = resExtract.EagleML.statusItem[0].reason[0].additionalData[0].Item as string;
                       
                            try
                            {
                               //method work for SMFGeneric objects only
                               object extractobject = getExtractObject(resExtract);
                            }
                            catch
                            {
                               //just in case
                            }                        
                        }
                        //catch any issues during eagleMl ws call
                        catch (Exception ee)
                        {
                            String errorMessage = ee.GetBaseException().Message;                       
                        }
                       
                    }
                }
                catch (Exception ex)
                {
                    throw;
                } 
            }
  8. Define the end point url and the account info(login/password).

  9. Create BasicHttpBinding, set security mode (security mode based on url schema http or https), credentials type (basic for EagleMLWebService ) and extend buffer size and message size.
  10. Make a small workaround for the response contentType, because current version MC sends a response with incorrect contentType:
  11. Make a fix for processing eagle non-soap messages to fix issue for some MC versions.
  12. Create a CustomTextMessagebindingElement class. 
  13. Create a CustomBinding object and a CustomTextMessagebindingElement object and copy HttpTransportBindingElement from the BasicHttpBinding object to the CustomBinding object.
  14. Create an EndPointAddress object using the end point url,create EagleMLPortTypeClient based on the end point address and the custom binding and set credentials.
    Now you are ready to make your first request.
  15. Prepare a RunTaskRequest message and execute the desired RunTaskRequest or RunTaskRequestSync method.