Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Example, How to run WebServices from C#, the easy way


Anyone who visited the ByD PDI workshops may remember the WebService examples with SoapUI.

Additionally, I want to explain another way of testing WebServices for ByD, which is IMHO way more easy

and closer to reality.

First of all, you need access to a ByD Studio and be able to create Solutions in there.

Second, if you don't have a Visual Studio C# 2010 installed already, go to Microsoft's homepage and grab a free Express version there. Of course, you also have to install it

For this example, I assume, that you want to do a 'Read' on a specific instance of your own BO.

In this case, we call our BO MasterDataWanneBe .

Quick guide for creating a WebService 'Read'

1. Create new WebService

1.1. Name: ReadAll

1.1.a. Namespace -> your soltion's namespace

1.1.b. Business object

1.2. Business Object View Name

1.2.a. Name = ReadAll

1.2.b. Select all Nodes + subnodes

1.3. Create u201AReadu2018 Service Operation

1.3.a. Name = Read

1.3.b. Select all nodes + subnodes

2. Activate WS

3. Create WS authentication file (.wsauth)

4. Add WS to authentication

5. Activate WSAuth (will create a view in background)

6. Assign created WS View + WS Workcenter

7. Authorize your user for this WorkCenter + View (in ByD, User Management)

8. Download WSDL, to for example: c:\ZAYQSY0Y_ReadAll.wsdl

Now you have a valid WSDL, pointing your solution and we go next to the more interesting part.

1. Start Visual Studio

2. Create a new Solution, Type = C# Console Application; project name = BydTest

3. Within the project explorer, right click on References, choose 'add service reference'

4. Click 'advanced' (bottom left)

5. Click 'Web reference' (bottom left)

6. Enter the downloaded WSDL file as URL, example: c:\ZAYQSY0Y_ReadAll.wsdl

7. It may happen, that there will be a security warning, just ignore it and the WSDL source should be displayed

8. Type in name 'ReadAll' as reference name

9. Press OK (the service 'ReadAll' will appear in the web reference list, within project explorer)

10. Type in the following C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BydTest.ReadAll;
using System.Net;

namespace BydTest
    class Program
        static void Main(string[] args)
            new Program().run();

        private void run()
            BydTest.ReadAll.service service = new BydTest.ReadAll.service();
            service.Credentials = new SuperSecretCredentials();
            MasterDataWanneBeReadAllByIDQueryMessage_sync request = new MasterDataWanneBeReadAllByIDQueryMessage_sync();
            request.MasterDataWanneBe = new MasterDataWanneBeReadAllByIDQuery();
            request.MasterDataWanneBe.ID = "MYTESTID"; // assuming, one instance with this ID exists!
            MasterDataWanneBeReadAllByIDResponseMessage_sync response;
            response = service.Read(request);
            if (response.Log.Item != null) foreach (BydTest.ReadAll.LogItem log in response.Log.Item)
                Console.WriteLine("Log: " + log.Note);
            if (response.MasterDataWanneBe != null)
                // This BO has to elements: 'ID' and 'RunStartDate'
                Console.WriteLine("My BO's ID:" + response.MasterDataWanneBe.ID);
                Console.WriteLine("My BO's StartDate:" + response.MasterDataWanneBe.RunStartDate.ToString());

    class SuperSecretCredentials : ICredentials
        public NetworkCredential GetCredential(Uri uri, string authType)
            return new NetworkCredential("myuser", "mypassword");

Example output, when selected ID was wrong:

Log: No instance found for specified key

Example output, when ID there is an existing BO instance with given ID:

My BO's ID:E5F42697_MKIRST
My BO's StartDate:18.05.2011 13:18:08

To my experience, this way is rock solid and I've never had any problems.

The two major pitfalls are:

Problem: System.Net.WebException, Message=Fehler bei der Anforderung mit HTTP-Status 401: Unauthorized

Solution: Check, if you're using the correct user ID. Most likely you're using an user alias and not the real user ID (generated IDs are most often longer than the shorter aliases)

Problem: SRT, RBAM authorization denied

Solution: Check if WorkCenter and WebService (Dummy-)View are assigned to your user. Sometimes it helps, re-activate your complete solution within ByD Studio AND/OR right click on your solution (ByD Studio) and choose 'Update Authorizations and Access Rights'

Not what you were looking for? View more on this topic or Ask a question