Search
Search

# .Net C# SOAP Web Service Client Example for SAP PI/PO Services

I was helping a friend connecting to a PO Web Service from .Net. It was not straightforward enough and I haven’t found a good example so I decided to share the code with you. For simplicity, It is a console application.

Features are:

• Using SOAP 1.1
• Basic authentication over HTTP
• Specifying endpoint

First, we add a Service Reference

We can give a Web URL or file path:

using ConsoleApplication4.ServiceReference2;

And the example code block:

static void Main(string[] args)
{

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

SI_SEND_ORG_DATAClient client = new SI_SEND_ORG_DATAClient(binding, endpoint);

ZHRS_SEND_ORG_LINE[] result = client.SI_SEND_ORG_DATA("1234");

System.Console.WriteLine(result[0].VORNA);
}

Regards,

Fatih

You must be Logged on to comment or reply to a post.
• Hi Fatih,

can you please create an example with the standard webService “Adapter Message Monitoring / basic? Style = document” and “getMessageList”?
So I have my problems with this.

best regards,

Alex

• Fatih Pense Post author

Hi Alexander,

I was able to use those services with SOAPUI and created a Java application using them in the past. I will try using C# when I have the time. Can you describe where you get stuck?

• Hi Fatih,

thx for your response but i solved  the issue by my self.

For the MessageList i use a simple HttpWebRequest like this

HttpWebRequest req = WebRequest.Create(Form1.url) as HttpWebRequest;
req.Credentials = new NetworkCredential(Form1.usr, Form1.pwd);

XmlDocument xmlDoc = new XmlDocument();
using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
{
xmlDoc.Save(Directory.GetCurrentDirectory() + @"\pi.xml");
}

best regards,

Alex

• Merhaba,

Öncelikle örnek için teşekkürler. Örnek üzerinden bende bir işlem yaptım fakat, result aldığım sırada

Tanınmayan ileti sürümü (Unrecognized message version) şeklinde bir hata almaktayım. Acaba binding yönteminde mi sorun var ya da SAP web servis ile ilgili bir ayar mı yapmak gerekiyor. Konu hakkında yardımcı olur musun ?

Teşekkürler.

• Hi Fatih,

We’ve been trying to develop a C# .NET console application that will integrate with SAP PI/PO web service though the following fictitious URL: https://webservicehost.com/XISOAPAdapter/MessageServlet?channel=B2B_SERVICEPROVIDER:PROJECT:SOAP_SND_SERVICEPROVIDER_Data

Whenever we run the console application the following exception is thrown everytime:

System.ServiceModel.Security.SecurityNegotiationException: could not establish secure channel for ssl/tls with authority ‘webservicehost.com’.

However, using SoapUI to test the connection, there’s no such error.

The obvious has been checked, like Certificate validity: it’s issued by GlobalSign and not self-signed, and it is not expired. The certificate path is correct and there are no errors pointed out on the Certificate when analysing it from a browser.

What could we be missing? If more information is needed, please let me know and I’ll complement this post.

• Hi Fatih! Thanks for the example

Is there any special consideration to make this example to be usable on a Sync Scenario? in my case, the “result” variable was setted as “Nothing” after call the function. I ran the service on SoapUI and it returns a message as response.

Regards!