我正在帮助一位朋友从 .Net 连接到 PO Web 服务。它不够简单,我还没有找到一个很好的例子,所以我决定与你分享代码。 为简单起见,它是一个控制台应用程序。
特点是:
使用 SOAP 1.1
基于 HTTP 的基本身份验证
指定端点
首先,我们添加一个服务引用
我们可以给出一个 Web URL 或文件路径:
将您的 C# 命名空间添加到主类。
using ConsoleApplication4.ServiceReference2;
以及示例代码块:
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();
}