【发布时间】:2018-08-03 10:16:35
【问题描述】:
我在使用 C# 编写的 Web 服务时遇到问题。在我想用参数调用方法之前它工作正常,使用我的 wsdl 从外部供应商生成的 SOAP 请求如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://127.0.0.1/AService</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">ANameSpace/login</Action>
</s:Header>
<soapenv:Body>
<ns1:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="ANameSpace">
<a_sDMSUserName xsi:type="xsd:string">test</a_sDMSUserName>
<a_sDMSUserPassword xsi:type="xsd:string">oscar</a_sDMSUserPassword>
</ns1:login>
</soapenv:Body>
</soapenv:Envelope>
这是我的Service接口的一部分:
[ServiceContract (Namespace ="ANameSpace")]
public interface IFordEcat
{
[OperationContract (Action ="ANameSpace/connect")]
int connect();
[OperationContract(Action = "ANameSpace/disconnect")]
int disconnect();
[OperationContract(Action = "ANameSpace/login")]
string login(string a_sDMSUserName, string a_sDMSUserPassword);
[OperationContract(Action = "ANameSpace/logout")]
string logout(string a_sSessionID, string a_sDMSUserName, string a_sDMSUserPassword);
使用 SoapUI 或通过服务参考在 C# 中设置测试客户端,它可以正常工作。
唯一的问题是登录方法或任何其他带有参数的方法的参数,在传递参数的节点中缺少名称空间前缀 (nsl)。例如,当我在 SOAPUi 中手动添加它们时,它就像魅力一样。有没有办法在不检查每个传入请求的情况下添加命名空间前缀?
非常感谢!
【问题讨论】:
标签: c# wcf soap namespaces