Skip to Content

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:

 

Add your C# namespace to the main class.

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;

	EndpointAddress endpoint = new EndpointAddress("http://hostname:port/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_SENDER_SYSTEM0&receiverParty=&receiverService=&interface=SI_SEND_ORG_DATA&interfaceNamespace=http://example.com/HR/OrganisationData");
	SI_SEND_ORG_DATAClient client = new SI_SEND_ORG_DATAClient(binding, endpoint);

	client.ClientCredentials.UserName.UserName = "Username";
	client.ClientCredentials.UserName.Password = "Password";

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

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

If you have any questions, please ask in the comments.

Regards,

Fatih

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member

    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

     

    (0) 
    1. 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?

      (0) 
      1. Former Member

        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.Load(resp.GetResponseStream());
              xmlDoc.Save(Directory.GetCurrentDirectory() + @"\pi.xml");
           }

         

        best regards,

        Alex

         

        (0) 
  2. Former Member

    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.

    (0) 
  3. Former Member

    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.

    (0) 

Leave a Reply