gpt4 book ai didi

c# - 添加自定义 SoapClient header

转载 作者:行者123 更新时间:2023-11-30 12:13:52 24 4
gpt4 key购买 nike

我是一个完全的 C# 新手,现在已经尝试破解这个几个小时但没有成功......

我需要构建一个 SoapClient 以在 C# 上使用...我一直在尝试将现有的 php 客户端移植到 c#。

基本上:我需要使用包含用户和密码的 Soap header 发出请求,这是我应该发送的 xml 示例。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://webservices.paymentmanager.mycheck.com">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>test</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<SOAP-ENV:Body>
<ns1:testws>
<ns1:x>1</ns1:x>
</ns1:testws>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我在完成时使用了 Visual Studio“添加服务引用...”

该服务运行良好,因为使用 php 它运行良好。

我构想的 C#:

namespace ConsoleApplication1
{
class Program
{
const String VENDOR_ID = "8723";
const String VENDOR_PASS = "test";
const String VENDOR_USER = "pass";
static void Main(string[] args)
{
try
{
PaymentManager.PaymentManagerPortTypeClient test = new PaymentManager.PaymentManagerPortTypeClient();
int num = test.testws(5);
Console.WriteLine(num);
}
catch( Exception e)
{
Console.WriteLine(e.ToString());
}
}
}

}

显然,我不知道如何实现 Soap header ,因此它抛出“缺少 SOAP header ”异常(从 WebService 接收到)。

最佳答案

我遇到了同样的问题。我找不到解决办法。最终我不得不创建整个 SOAP 消息并通过 HTTPWebRequest 发送它。

看看here .

关于c# - 添加自定义 SoapClient header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10870340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com