RKL eSolutions Blog Trends and Insights

5 days of Sage X3 Web Services v12 Day 5

Day 5 Consuming X3 Subprogram Web Services from .Net

This is Part 5 of a 5 part series on creating and consuming web services for Sage X3 Version 12. This part will focus on consuming subprogram based web services from .Net. In Part 1 we discussed setup of a Sage X3 Web Services Pool, and in Part 2 we discussed creating and publishing web services based on X3 objects and subprograms, and in Part 3 we discussed using the X3 web services tester to test and evaluate web services, and in Part 4 we discussed calling X3 object-based web services from a .Net program.

Consuming X3 Web Services in .Net

X3 Web Services can be consumed from .net by using the web services WSDL from X3.  Below are the steps to creating a new .Net project to consume X3 web services.  To get started with the solution, instructions on adding the WSDL and creating the authorization class are covered in the blog post for Day 4, which covers creating the initial .net application for web service consumption.

Initialize the Context

Below is a sample .net context initialization.

  • X3 Language - i.e. “ENG”
  • X3 WS Pool – this is the name of the web service pool defined in X3. This may or may not be the same as the endpoint, depending on how it was set up.
  • Context – variable properties are defined here, including the return format (XML or JSON).
  • Web Services Endpoint – this is added to the .config file by default when the WSDL is added to the project, but it can be changed. It should be specified here to override the original definition.
  • Credentials – this is an X3 user. The user must be set up in X3 to allow web services access.
  • Timeout – this can be increased if timeouts are occurring in web service calls.
  • Object Keys – these are required for some types of web service calls, to read/update specific record, etc.

WS5 X3 .net context initiaWS5 X3 .net context initialization

Error Handling

  • The web service resultXML will contain a status of 0 (failed) or 1 (successful)
  • If the status is 0, the error messages will be returned as an array of type CAdxMessage. These can be evaluated for severity, along with the message text.
If the status is 1, the web service was successful. The web service result can be deserialized from an XML or JSON string into a pre-defined class.
WS5 X3 error handling-2

Call an X3 Subprogram Web Service

Calling a web service that was published from an X3 subprogram requires use of the “run” method from the web services.  Below is an example of the calling the YWSCUSTLIS subprogram that we created in the Day 2 series.

1. The first step is the initialize the call context and the basic authentication properties.

2. If the status is 1, the web service was successful. The web service result can be deserialized from an XML or JSON string into a pre-defined class.

3. The pre-defined class that the results are deserialized into is shown below.

WS5 X3 deserialized-1

4. Below is the full code.

WS5 Call an X3 Subprogram Web Service

Conclusion

You have now learned how to create a .net program to consume a subprogram-based web service.

More in this series

Day 1 - Creating a Classic SOAP Pool

Day 2 - Creating and Publishing Web Services

Day 3 - Testing Web Services

Day 4- Consuming Web Services in .NET

Day 5 - Consuming X3 Subprogram Web Services from .Net


 

GOT QUESTIONS ABOUT WEB SERVICES FOR SAGE X3?

Contact us if you want to learn more about Sage ERP X3 Web Services features or to request help with your system.

Contact RKL eSolutions

Tags: Sage X3
RKL Team

Written by RKL Team

Since 2001, RKL eSolutions has helped growing companies maximize their technology resources and investment. Over the years, we have helped hundreds of small and medium sized businesses as their strategic business partner. We specialize in the needs of Entertainment, Software & SaaS, Professional Services, Manufacturing, and Non Profit organizations. Our experienced consultants have a passion for making every facet of your business successful and are intent on building a long-term relationship with every client.