How to create VS2015 Class Library or WebAPI, or WCF to consume JDE BSSV WSDL?

marcus.net

Member
Hi all,

This is my first post to the community so please be kind :)

I was tasked to create a .NET client to consume these WSDLs:
//http://xxx.x.x.xxx:yyyy/DV910/AddressBookManager?wsdl
//http://xxx.x.x.xxx:yyyy/DV910/CustomerManager?wsdl

I have scoured the usual online resources and could not find any helpful/current examples for Visual Studio 2015 C#.
Here are some links that I did find but are not useful as they are too old (VS2005!) or rely on JDE specific tools.



Should this be a WCF, WebAPI, or standard Class Library project?

I have added the "Web Reference" to a Class Library (Add Service Ref->Advanced->Add Web Ref) but am stuck with simple things like how to create an ICredentials object to log in - and after that ?????

I have created a WCF but am drowned out by the amount of coding overhead (first WCF for ME!!) and have lost track of the forest through the trees

What I'm really looking for is documentation of a shell project that:
  1. adds the JDE WSDL web reference (URL)
  2. gives an example for connecting to the service (login/auth)
  3. calls a method on the jde object (getCustomerV2) with a parameter
  4. process the result in some sort of meaningful way

here is an example of the type of code I'm loooking for ... just for VS2015
(the following code uses Microsoft WSE 2.0 SP2 which is not current)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Protocols;
using JDEWebService.JDE_AddBookMgr_WebReference; //the webreference
using System.Web.Services;
using Microsoft.Web.Services2.Security.Tokens; //Microsoft WSE 2.0 SP2
using System.Net;

namespace webserviceJDE
{
class Program
{
static void Main(string[] args)
{
string username = "jde";
string password = "jde";
UsernameToken ut = new UsernameToken(username, password, PasswordOption.SendPlainText); //Create Security token...


RI_AddressBookManager abm = new RI_AddressBookManager();//RI_AddressBookManager();
NetworkCredential myCred = new NetworkCredential(username, password);
abm.RequestSoapContext.Security.Tokens.Add(ut);
RI_GetAddressBook a = new RI_GetAddressBook();//Selection Parameters
a.entityTypeCode = "E"; //just look for employees
RI_ShowAddressBook S = abm.getAddressBook(a);
if (S != null)
{
foreach (RI_AddressBook ab in S.addressBook)
{
Console.WriteLine(ab.entityName);
}
}
}
}
}

Here is my attempt:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using JDEWebService.JDE_CustMgr_WebReference;
using JDEWebService.Properties;


namespace JDEWebService
{
public class JDEWebService
{
public string TEST()
{
ICredentials credentials = new NetworkCredential("XXXXXX", "YYYYYYYYY");
getCustomerV2 customer = new getCustomerV2();

using (CustomerManagerService service = new CustomerManagerService())
{
service.Credentials = credentials;
service.getCustomerV2(customer);
}
return "done";
}
}
}

Any and all suggestions would be greatly appreciated.
ty - marcus
 

nkuebelbeck

VIP Member
first things first, does your BSSV work? test it with something like soupui or postman(chrome plugin)
see attached for a sample of something i've done in the past.
 

Attachments

  • trythis.txt
    2.2 KB · Views: 21

ONYX

Well Known Member
Hello marcus,
Type of the application doesn't matter as long as you can use Service Reference and necessary technologies in the project.
Do not forget to import BSSV Service Reference (wsdl) to your project.
I have invoked bssv from windows console applications, windows services, SSIS packages and WCF services.

I had to chop the code a little bit and put everything you need in one spot (function).

This was my first attempt to invoke bssv from .NET (MS SQL Server Integration Services) -> my first .NET application.
Please do not blame me for breaking all the rules of OOP and .NET programming :)

Code:
using System;
using System.Data;
using System.Data.Odbc;
using System.ServiceModel;
using SC_e38bf3cad2fe4046a05e18a7747d6e9e.ServiceSalesOrderManager;
using SC_e38bf3cad2fe4046a05e18a7747d6e9e;
using System.ServiceModel.Channels;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Serialization;
using System.IO;

public class ScriptMain : UserComponent
{
    public ProcessSalesOrderV4 request = null;
    public ConfirmSalesOrderV4 response = null;

  public void create_JDE_SalesOrder()
    {
        request = new ProcessSalesOrderV4();
        response = new ConfirmSalesOrderV4();

        string strErrors = "";
        string strException = "";
        bool blnDontExe = false;

        BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
        binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
        binding.MaxBufferSize = 2147483647;
        binding.MaxBufferPoolSize = 2147483647;
        binding.MaxReceivedMessageSize = 2147483647;
        EndpointAddress url_SalesOrderManager = new EndpointAddress(this.Variables.JDEBSSVServerURL + "SalesOrderManager");

        Oracle_E1_SBF_JWS_PkgBldFile_SalesOrderManagerClient client = null;

        try
        {
            client = new Oracle_E1_SBF_JWS_PkgBldFile_SalesOrderManagerClient(binding, url_SalesOrderManager);
        }
        catch (System.InvalidOperationException ex)
        {
            strException = ex.ToString();
            strErrors = ex.ToString();
        }
        catch (System.UriFormatException ex)
        {
            strException = ex.ToString();
            strErrors = ex.ToString();
        }
        if (client == null)
        {
            blnDontExe = true;
        }

        try
        {
            client.ClientCredentials.UserName.UserName = this.Variables.JDEBSSVServerUserName;
            client.ClientCredentials.UserName.Password = this.Variables.JDEBSSVServerPassword;
            BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
            elements.Find<SecurityBindingElement>().IncludeTimestamp = false;
            client.Endpoint.Binding = new CustomBinding(elements);
            client.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 0);
        }
        catch (System.InvalidOperationException ex)
        {
            strException = ex.ToString();
            strErrors = ex.ToString();
        }
        catch (System.UriFormatException ex)
        {
            strException = ex.ToString();
            strErrors = ex.ToString();
        }
        if (client == null)
        {
            blnDontExe = true;
        }

        try
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender1, certificate, chain, sslPolicyErrors) => true);
        }
        catch (Exception ex)
        {
            blnDontExe = true;
            strException = ex.ToString();
            strErrors = "Error overriding the server certificate validation";
        }
        if (blnDontExe == false)
        {
            try
            {
                request.Header.Processing.ActionType = "A";
                request.Header.Processing.ProcessingVersion = "XXX";
                request.Header.SalesOrderKey.DocumentTypeCode = "SO";
                request.Header.BusinessUnit = "100";
                request.Header.Company = "00001";

                response = client.processSalesOrderV4(request);
            }
            catch (System.ArgumentException ex)
            {
                strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                strException = ex.ToString();
                Console.Out.WriteLine(strException);
            }
            catch (System.ServiceModel.Security.SecurityAccessDeniedException ex)
            {
                strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                strException = ex.ToString();
                Console.Out.WriteLine(strException);
            }

            catch (System.ServiceModel.EndpointNotFoundException ex)
            {
                strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                strException = ex.ToString();
                Console.Out.WriteLine(strException);
            }
            catch (System.ServiceModel.Security.SecurityNegotiationException ex)
            {
                strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                strException = ex.ToString();
                Console.Out.WriteLine(strException);
            }
            catch (System.ServiceModel.FaultException ex)
            {
                strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                strException = ex.ToString();
                Console.Out.WriteLine(strException);
            }
            catch (System.ServiceModel.Security.MessageSecurityException ex)
            {
                strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                strException = ex.ToString();
                Console.Out.WriteLine(strException);
            }
            catch (System.TimeoutException ex)
            {
                strErrors = "Error Connection Timed out : check the network connection and whether the port is correct : " + ex.Message + "\n\n" + ex.StackTrace;
                strException = ex.ToString();
                Console.Out.WriteLine(strException);
            }
        }

        if (!strException.Equals(string.Empty))
        {
            AddNotification(
                request.Header.CustomerPO,
                this.Variables.InterfaceID,
                this.Variables.InterfaceID,
                "Error found in PO # " + request.Header.CustomerPO,
                strErrors + "<br>",
                "1",
                "");

            if (!strException.Equals(string.Empty))
                AddNotification(
                    request.Header.CustomerPO,
                    this.Variables.InterfaceID,
                    this.Variables.InterfaceID,
                    "Error found in PO # " + request.Header.CustomerPO,
                    "Detailed exception information : <br>" + strException + ".<br>",
                    "1",
                    "");

            strTransactionStatus = "250";
        }
        else
        {
            // Get recipient from "who-is-who"
            try
            {
                get_JDE_WhoIsWho(dict_Sales_Orders[request.Header.CustomerPO]);
            }
            catch (Exception)
            {
                throw;
            }

            // Get sales order details
            try
            {
                get_JDE_SalesOrderDetails(response);
            }
            catch (Exception)
            {
                throw;
            }

            strTransactionStatus = "300";
        }
    }
}
 
hi onyx,

i TRIED TO LOAD SAME Program but found error as below

System.NullReferenceException: 'Object reference not set to an instance of an object.'
WebAPI.SalesOrderManagerAPI.processSalesOrderV4.header.get returned null

My Code is As below:

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using WebAPI.SalesOrderManagerAPI;
using HttpGetAttribute = System.Web.Http.HttpGetAttribute;
using HttpPostAttribute = System.Web.Http.HttpPostAttribute;
using RouteAttribute = System.Web.Http.RouteAttribute;

using System;
using System.Data;
using System.Data.Odbc;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Serialization;
using System.IO;

namespace WebAPI.Controllers
{
    public class WebController :  ApiController
    {
        public processSalesOrderV4 request = null;
        public confirmSalesOrderV4 response = null;



        [HttpGet]
        [Route("WebController/GetData")]
        public string GetData()
        {
            create_JDE_SalesOrder();
            return "Welcome To Web API";
        }


        public void create_JDE_SalesOrder()
        {
            request = new processSalesOrderV4();
            response = new confirmSalesOrderV4();

            string strErrors = "";
            string strException = "";
            bool blnDontExe = false;

            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            binding.MaxBufferSize = 2147483647;
            binding.MaxBufferPoolSize = 2147483647;
            binding.MaxReceivedMessageSize = 2147483647;
            EndpointAddress url_SalesOrderManager = new EndpointAddress("https://xyz/SalesOrderManager");

            SalesOrderManagerClient client = null;

            try
            {
                client = new SalesOrderManagerClient(binding, url_SalesOrderManager);
            }
            catch (System.InvalidOperationException ex)
            {
                strException = ex.ToString();
                strErrors = ex.ToString();
            }
            catch (System.UriFormatException ex)
            {
                strException = ex.ToString();
                strErrors = ex.ToString();
            }
            if (client == null)
            {
                blnDontExe = true;
            }

            try
            {
                client.ClientCredentials.UserName.UserName = "xyz";
                client.ClientCredentials.UserName.Password = "xyz";
                BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
                elements.Find<SecurityBindingElement>().IncludeTimestamp = false;
                client.Endpoint.Binding = new CustomBinding(elements);
                client.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 0);
            }
            catch (System.InvalidOperationException ex)
            {
                strException = ex.ToString();
                strErrors = ex.ToString();
            }
            catch (System.UriFormatException ex)
            {
                strException = ex.ToString();
                strErrors = ex.ToString();
            }
            if (client == null)
            {
                blnDontExe = true;
            }

            try
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender1, certificate, chain, sslPolicyErrors) => true);
            }
            catch (Exception ex)
            {
                blnDontExe = true;
                strException = ex.ToString();
                strErrors = "Error overriding the server certificate validation";
            }
            if (blnDontExe == false)
            {
                try
                {
                    request.header.processing.actionType = "A";
                    request.header.processing.processingVersion = "M3000001";
                    request.header.salesOrderKey.documentTypeCode = "SO";
                    request.header.businessUnit = "30010";
                    request.header.company = "00300";

                    response = client.processSalesOrderV4(request);
                }
                catch (System.ArgumentException ex)
                {
                    strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                    strException = ex.ToString();
                    Console.Out.WriteLine(strException);
                }
                catch (System.ServiceModel.Security.SecurityAccessDeniedException ex)
                {
                    strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                    strException = ex.ToString();
                    Console.Out.WriteLine(strException);
                }

                catch (System.ServiceModel.EndpointNotFoundException ex)
                {
                    strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                    strException = ex.ToString();
                    Console.Out.WriteLine(strException);
                }
                catch (System.ServiceModel.Security.SecurityNegotiationException ex)
                {
                    strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                    strException = ex.ToString();
                    Console.Out.WriteLine(strException);
                }
                catch (System.ServiceModel.FaultException ex)
                {
                    strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                    strException = ex.ToString();
                    Console.Out.WriteLine(strException);
                }
                catch (System.ServiceModel.Security.MessageSecurityException ex)
                {
                    strErrors = "Error " + ex.Message + "\n\n" + ex.StackTrace;
                    strException = ex.ToString();
                    Console.Out.WriteLine(strException);
                }
                catch (System.TimeoutException ex)
                {
                    strErrors = "Error Connection Timed out : check the network connection and whether the port is correct : " + ex.Message + "\n\n" + ex.StackTrace;
                    strException = ex.ToString();
                    Console.Out.WriteLine(strException);
                }
            }

            if (!strException.Equals(string.Empty))
            {
                //AddNotification(
                //    request.header.CustomerPO,
                //    this.Variables.InterfaceID,
                //    this.Variables.InterfaceID,
                //    "Error found in PO # " + request.header.CustomerPO,
                //    strErrors + "<br>",
                //    "1",
                //    "");

                //if (!strException.Equals(string.Empty))
                //    AddNotification(
                //        request.header.CustomerPO,
                //        this.Variables.InterfaceID,
                //        this.Variables.InterfaceID,
                //        "Error found in PO # " + request.header.CustomerPO,
                //        "Detailed exception information : <br>" + strException + ".<br>",
                //        "1",
                //        "");

                //strTransactionStatus = "250";
            }
            else
            {
                // Get recipient from "who-is-who"
                //try
                //{
                //    get_JDE_WhoIsWho(dict_Sales_Orders[request.header.CustomerPO]);
                //}
                //catch (Exception)
                //{
                //    throw;
                //}

                //// Get sales order details
                //try
                //{
                //    get_JDE_SalesOrderDetails(response);
                //}
                //catch (Exception)
                //{
                //    throw;
                //}

                //strTransactionStatus = "300";
            }
        }

    }
}

Please Help.
 

ONYX

Well Known Member
Hi tejasklodha,
Well sample code in the post is not a self sufficient/contained .net application to invoke a BSSV call.
It is rather a rough idea how to invoke a service .
You need to satisfy some prerequisites before you can actually call a service.

I would suggest looking at your \\deployment_server \E920\system\Classes\samples\DotNet\ for more details.

Regards,
Serge
 
Top