[英]How do I add a custom header to a SOAP request using C#?
I'm connecting to a RemObjects SDK SOAP server written in Delphi using a C# client. 我正在使用C#客户端连接到用Delphi编写的RemObjects SDK SOAP服务器。 I can make the initial login, but subsequent requests require a custom SOAP header that looks like this: 我可以进行初始登录,但是后续请求需要一个自定义的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>
My existing code looks like this: 我现有的代码如下:
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);
}
}
}
How do I add the custom header to the request? 如何将自定义标头添加到请求中? Please bear in mind that I am currently completely ignorant of C#. 请记住,我目前完全不了解C#。
With help from RemObjects we finally got this working. 在RemObjects的帮助下,我们终于完成了这项工作。 If anyone is interested, they have produced an article explaining how it is done. 如果有人感兴趣,他们会写一篇文章来说明如何完成。 You can find it http://wiki.remobjects.com/wiki/WIP:Consuming_RemObjects_SOAP_services_with_third_party_clients 您可以找到它http://wiki.remobjects.com/wiki/WIP:Consuming_RemObjects_SOAP_services_with_third_party_clients
如果随后的请求期望一个Soap Header,则UtilsClient应该公开一个可以设置的属性,例如SoapHeaderValue。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.