我正在使用.NET Core 2.1与我们拥有的旧版SOAP Web服务集成。
C#代码
"No route found for "CONNECT /www.baidu.com:443""
从服务器返回的XML(通过Fiddler捕获)
[DataContract(Name = "registerResponse", Namespace = "urn:svcnet")]
public class RegisterResponse
{
[DataMember(Name = "sessionKey")]
public string SessionKey { get; set; }
}
[ServiceContract(Name = "svcnet", Namespace = "urn:svcnet")]
public interface IRegister
{
[OperationContract(Name = "register")]
RegisterResponse Register(string param1);
}
public class MyContext
{
public void Register()
{
var serviceUrl = "https://myserviceurl";
var endpoint = new EndpointAddress(new Uri(serviceUrl));
var factory = new ChannelFactory<IRegister>(binding, endpoint);
IRegister channel = factory.CreateChannel();
var result = channel.Register("somevalue"); // <<< result is always null
}
}
结果始终为null。在Google和Stack Overflow上花费了多个小时后,我使自己确信它静默地未能构造响应对象。有什么线索可以调试它,还是我的代码明显有问题?
我也尝试了以下方法,但结果相同(总是为空)
<?xml version="1.0" encoding="utf-16"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:svc="urn:svcnet">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<svc:registerResponse>
<sessionKey>ABC123</sessionKey>
</svc:registerResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>