SAP for Utilities Blogs
Discover insights and practical tips to optimize operations, reduce costs, and deliver reliable energy with SAP technology. Contribute your own blog post!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

            Supporting lots of different platforms such as mobile, desktop and web applications can be difficult and expensive for any organization. There should be an easy and generic way to consume data services across any platform with only having to change the UI. This can be achieved by using the SAP Multichannel Foundation for Utilities (MFU).    MFU is a service layer that is pre-integrated with SAP CRM and IS-U and exposes backend business processes by way of OData services.  Because of OData’s very nature, these OData services can be consumed by any platform that can process XML/JSON responses over HTTP. OData provides a standard protocol for CRUD operations.


In principle OData services are seamlessly consumable from any platform and so is SAP’s Multichannel Foundation for Utilities. However, for the purpose of this blog post, my focus is on consuming MFU OData services using Microsoft C# to demonstrate the strength of MFU and to show how quickly I can build a UI with very basic knowledge of CRM/IS-U.

For our small example, we will implement the following process flow:


First Setup you HttpClient with the following code:




            using (var handler = new HttpClientHandler { Credentials = new NetworkCredential("user", "password") })
            using (var client = new HttpClient(handler))
            {
                client.BaseAddress = new Uri("https://xxxxxxxxxxxxxxxxxxxxxx/sap/opu/odata/sap/CRM_UTILITIES_UMC/Accounts('1826')/");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var result = client.GetAsync("ContractItems").Result;
                result.EnsureSuccessStatusCode(); // throws exception if Status code is not 200
            }


We first create a HttpClientHandler object which handles the NetworkCredential for username and password.  We pass this object to the HttpClientIn the HttpClient, we setup the base address to our the landscape.  We add headers to get a json response.  We then call our entity “ContractItems” and we will get an  asynchronous response.  We have to ensure the result returns a status code of 200 or else an exception will be thrown since the user will not be authorized.  The next thing we have to do is generate c# classes for our response when we deserialize the data.  The is what our object will look like for a ContractItem:



        public class Result
        {
            public Metadata __metadata { get; set; }
            public string NewServiceProviderID { get; set; }
            public string Distributor { get; set; }
            public string SwitchServiceFlag { get; set; }
            public string MeterNumber { get; set; }
            public string FormerServiceProviderID { get; set; }
            public string ContractID { get; set; }
            public string Description { get; set; }
            public string ContractItemGUID { get; set; }
            public string ContractHeaderGUID { get; set; }
            public DateTime ContractStartDate { get; set; }
            public DateTime ContractEndDate { get; set; }
            public string AccountID { get; set; }
            public string BusinessAgreementID { get; set; }
            public string ProductID { get; set; }
            public string DivisionID { get; set; }
            public string PointOfDeliveryGUID { get; set; }
            public string PremiseID { get; set; }
            public Premise Premise { get; set; }
            public Product Product { get; set; }
            public BusinessAgreement BusinessAgreement { get; set; }
            public Division Division { get; set; }
        }


Now that we have created the required classes to deserialize the response object, we added the following code.



JsonConvert.DeserializeObject<RootObject>(result.Content.ReadAsStringAsync().Result);



Now Propagate the List of contract results to the a GridView control on the UI.


this.ContractsView.DataSource = contractsEntity.d.results;
this.ContractsView.DataBind();


End Result:

Conclusion:  I created a simple web page (showing a list of contracts) in about an hour and with very little knowledge of CRM/IS-U to demonstrate how with such little effort, a client application can be developed to consume MFU.


Full source code is attached for ASP.NET.

Top kudoed authors