我正在使用 C# 客户端连接到用 Delphi 编写的 RemObjects SDK SOAP 服务器。我可以进行初始登录,但后续请求需要一个自定义 SOAP 标头,如下所示:
<SOAP-ENV:Header SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS1="urn:MyAPI">
<NS1:ROClientIDHeader xsi:type="NS1:ROClientIDHeader">
<ID xsi:type="xsd:string">{3EC5A9DF-C6DC-4BFB-8134-37DDCF07910D}</ID>
</NS1:ROClientIDHeader>
</SOAP-ENV:Header>
我现有的代码如下所示:
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Create a new instance of the login service
MyLibrary.LoginServiceClient LoginClient = new MyLibrary.LoginServiceClient();
// Call the Login method on the server
MyLibrary.TLoginInfo LoginInfo = LoginClient.Login("Administrator", "master", 0, 0, MyLibrary.TClientType.ctWindowsClient);
// Set the Session ID
var SessionID = LoginInfo.SessionId;
// Create a new instance of the Utils service
MyLibrary.UtilsClient UtilsClient = new MyLibrary.UtilsClient();
// Set the SOAP header //
// <SOAP-ENV:Header SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:NS1="urn:EasyIPv6API">
// <NS1:ROClientIDHeader xsi:type="NS1:ROClientIDHeader">
// <ID xsi:type="xsd:string">{3EC5A9DF-C6DC-4BFB-8134-37DDCF07910D}</ID>
// </NS1:ROClientIDHeader>
// </SOAP-ENV:Header>
// Make the call
var AddResult = UtilsClient.AddValues(1, 1);
}
}
}
如何将自定义标头添加到请求中?请记住,我目前对 C# 完全一无所知。