我是一名完全不懂C#的新手,已经尝试了几个小时但没有成功...
我需要构建一个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#中却不起作用。
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接收到的)。