No matter how frumpy SAP may look most of the time, nevertheless you can build such modern things like web services inside the SAP system. Even the WSDL (Web Service Description File) file can be generated in SAP. I read about this feature (WSDL generation) just at the right time, because recent days I should write a web service in SAP which should be triggered by a C# application.
In .NET web services can easily integrated via their WSDL file by using the WebReference feature of Visual Studio. Therefore Visual Studio generates a so-called proxy class from the given WSDL file which can be used to call all functions of the webservice without thinking too much.
As far as in theory. In practice I had to choose the security mode for the web service in SAP. This mode affects how a user/client/consumer has to authenticate himself against the web service. For my web service I had choosen BasicAuth as security mode. (BasicAuth is a simple authentification model which is based on username and password.)
Unfortunately Visual Studio refuses to do a good job when generating the proxy class from SAP’s WSDL file. Namely it generates the proxy class but however it deranges the authentification code. So if you create an object of the proxy class and try to call any of the web service’s methods you will get an error message like this one:
“The HTTP request is unauthorized with client authentication scheme ‘Anonymous’. The authentication header received from the server was ‘Basic realm=”SAP Web Application Server XYZ”‘.”
SAPwebservice.YS_TEST_SERVICE sapClient = new SAPwebservice.YS_TEST_SERVICE(); sapClient.ClientCredentials.UserName.UserName = "my_username"; sapClient.ClientCredentials.UserName.Password = "my_password"; int result = sapClient.TestMethod("1234", "My test data.");
And I even had passed my username and my password in foresight. So how to fix this?
In order to “teach” the generated proxy class to use BasicAuth with credentials in the right way to communicate with the SAP web service, it is necessary to pass the following parameters to the constructor of the proxy class.
using System.ServiceModel; [...] //Manually reconfigure the binding for SAP-BasicAuth BasicHttpBinding basicAuthBinding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); basicAuthBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; EndpointAddress basicAuthEndpoint = new EndpointAddress("http://my_sap_server:mein_port/sap/bc/srt/rfc/sap/my_webservice?sap-client=my_client&wsdl=1.1"); SAPwebservice.YS_TEST_SERVICE sapClient = new SAPwebservice.YS_TEST_SERVICE(basicAuthBinding, basicAuthEndpoint);
If you create the binding by hand, you can specify the authentication method. In this way you can persuade the proxy class to use the credentials (my_username and my_password) we set up in the code above.
That’s the way to use SAP web services in combination with C#/.NET clients.
Anyone who has already written one or the other program in Visual Studio with C# probably knows the following problem. Sometimes you use different libraries (Dlls) from different developers/vendors. Partly also libraries that fulfill similar purposes. This might go well, but it doesn’t have to.
Often you will get confronted with an error message like this: “‘XYZ’ is an ambiguous reference between ‘LibraryA.XYZ’ and ‘LibraryB.XYZ’”
What next? In the following I’ll explain how to solve this kind of error by taking the example of the AForge library. For instance we profess that we included the following using-directives into our program.
using System.Drawing; using AForge.Imaging;
So now, if we use the class “Image” in our program, we will see the following error message, which result from the fact that there are two “Image” classes referenced. One in the System.Drawing namespace as also one in the AForge.Drawing namespace. Visual Studio (and later on it’s compiler) doesn’t know which Image class to use.
One way to solve this would be to weigh which one of the both classes is used more frequently and then remove the using-directive for the namespace which contains the implementation which is used less frequently. But then you had to specify the full path everytime you want to use the class which isn’t referenced as using directive.
Image img = AForge.Imaging.Image.FromFile(imagePath);
However this is (depending on the number of calls of this class and the length and nesting of the namespaces) really awkward.
Much simpler and more elegant (atleast to my mind) is to make an alias for a namespace. Setting an alias can be done directly when setting up the using directive. On the basis of our example, we could rewrite the Aforge using directive as follows.
using System.Drawing; using AF = AForge.Imaging;
From now on we always can write a simple “AF.” instead of the much longer “AForge.Imaging.”. On the one hand this solves the problem of the ambiguous references and on the other hand it helps us to easily distinguish between the different references.
Image img = AF.Image.FromFile(imagePath);
This was easy, wasn’t it? Now let me know if you already used namespace aliases or if this topic was news to you?
When it comes to secure file transfer, one or the other of you should probably have heard of the SFTP-client named WinSCP. WinSCP enables the secure transfer of data between two computers based on either the SSH protocol or the SFTP protocol and provides, as also many of the normal FTP-clients do, the functionality of editing files directly on the server (respectively edit them direct out of the WinSCP interface without the premise to manually download the files before editing).
Unfortunately WinSCP will open all text files in his own simple style editor. But if you want to edit script files like PHP scripts, which is what I want to do most times, you will miss the comfort of a good text editor like Notepad++ or Sublime Text. But don’t worry – there’s a solution also for this problem, so that you don’t have to give up your beloved features like syntax highlighting and autocomplete. How to connect WinSCP with the editor of you choice is what I’ll show to you in the following senteces. (For this article we pretend Notepad++ is our favourite text editor.)
After you have opened WinSCP you will see the login screen with a tree menu at the left hand. Click on the “Preferences” menu item and then on the “Preferences…” button on the right side.
Now switch to the subitem named “Editors”. At this point you can add, edit and remove editors for different file formats. So if you have configured different editors for different file types WinSCP will open your preferred editor everytime you click on the “Edit” button in the WinSCP file manager. To add a new editor simply click on the “Add …” button.
Choose the option “External editor:”, click on the “Browse…” button and select the path to the Notepad++ executable file. Now you have to define for which file types Notepad++ should be opened. If you want to use Notepad++ for all kind of file types just enter “*.*”. The asterisks are acting as wildcards. That means “*.*” is equally to “any-filename.any-filetype”. If you want to use Notepad++ only for PHP files you should enter this “*.php”.
If you’ve done everything allright, Notepad++ should be available out of WinSCP from now on. To proof if everything is ok, open WinSCP and log into one of your servers. Now rightclick on any (text-)file and click on the “Edit” menu entry and WinSCP should automatically download the file and open it in editmode in Notepad++. If you’ve done your changes, save the file in Notepad++ and WinSCP will automatically upload it to the server. So that’s how coding makes fun!
I hope the article was understandable. Nevertheless, if you have any questions, just write me a comment below this post.
I already wrote about how you can boot directly into the classic desktop in Windows 8. However those, who do not like to get their hands dirty while working with the Windows registry or just want quickly switch back and forth, should pay me their close attention for a moment. I developed a tiny tool which is called Win8 BTD where BTD stands for Boot To Desktop.
Win8 BTD is a small tool written by me, which does not more or less than to set the appropriate settings in the registry, so that Windows 8 launches directly into the classic desktop. Of course, any changes made can also be undone with a single click, if you would rather want to start again directly into the new tile view.
The tool requires .NET framework 4.5, which is, however, included in Windows 8. About feedback or requests for changes I would be very happy as always.
Meanwhile everybody should have seen or atleast heard of the new user interface which comes with Windows 8. One of the big changes is that your computer will directly boot into the new tile-(start-)menu. I personally do not mind about that, but I’ve heard of many people who would like to boot directly into the (classic) desktop view without beeing confronted with the metro/tile-view at first. Nothing easier than that.
To boot directly into the classic desktop, only one value needs to be adjusted in the registry. What it is and how it needs to be changed, I want to show you briefly below.
At first you have to open the registry. (Therefore either search for “regedit” in the apps menu or start the “Run as”-dialog by pressing Win+R and then enter “regedit”.)
Navigate to the following key (as shown in the screenshot above):
There you will find a key-value-pair with the name “Shell”.
Change the value of the Shell entry from “explorer.exe” to “explorer.exe /select,explorer.exe” and confirm the changes by clicking “OK”. From the next reboot on, you will boot directly into the classic desktop. If you want to reverse your changes and boot back into the ModernUI tile view, you only need to change the value of Shell back to “explorer.exe” and reboot once again.