我是一个完整的C#新手,一直在努力,现在没有成功破解这对于几个小时......添加自定义SoapClient的头
我需要建立一个SoapClient的对C#使用...我一直在尝试将现有的PHP客户端移植到C#中。
基本上:我需要使用包含用户名和密码的Soap头进行请求,这是我应该发送的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#我已经concieved:
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头,所以它抛出一个“缺少SOAP头”异常(这是从WebService收到)。
如果我得到你的答案,有必要修改服务实现,不是吗?如果您无法使用这些服务,该怎么办? –
@ADC你的意思是服务器端?没有这个例子只是描述了如何创建一个肥皂呼叫(客户端)。 – Anas
我不同意。建议的解决方案指出:“为了强制使用我们的新SOAP头,我们需要在我们的方法中添加以下属性:[...]”。所以看起来该服务必须进行修改。 –