【发布时间】:2019-11-19 08:56:31
【问题描述】:
我正在尝试使用 C# 和 WCF 创建一个 SOAP 客户端。
我的环境:
- Visual Studio 2019
- .net Core 3.0 MVC 项目
- 带有基本身份验证的 WSDL 网址
代码:
AccountServicePortClient.EndpointConfiguration configuration = new AccountServicePortClient.EndpointConfiguration();
AccountServicePortClient client = new AccountServicePortClient(configuration);
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
client.Endpoint.Binding = binding;
client.ClientCredentials.UserName.UserName = "XXX";
client.ClientCredentials.UserName.Password = "XXX";
Task<CheckAddressSuccess> success = client.checkAddressAsync(*Some Arguments*);
success.Wait();
CheckAddressSuccess successResult= success.Result;
收到结果时,我得到一个 ArgumentException:
“System.Xml.XmlNode[]”类型的对象无法转换为“ServiceReference2.CheckAddressSuccess”类型
有人知道我该如何解决这个问题吗?
更新:
客户端是通过将 WSDL URL 添加为 WCF 提供程序来创建的。我没有构建肥皂服务。我已经发现 SOAP 响应 CheckAddressSuccess 在命名空间中有错字(“http ...”而不是“https ...”)。我想使用 WCF DataContractSerializer。我怎样才能做到这一点?
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.ServiceModel.ServiceContractAttribute(Namespace="https://XXX/account", ConfigurationName="ServiceReference2.AccountServicePort")]
public interface AccountServicePort
{
[System.ServiceModel.OperationContractAttribute(Action="https://XXX/account#checkAddress", ReplyAction= "*")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style = System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults = true, Use = System.ServiceModel.OperationFormatUse.Encoded)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
System.Threading.Tasks.Task<ServiceReference2.CheckAddressSuccess> checkAddressAsync(string transactionId, ServiceReference2.Address address, bool checkHousenumberAdditive);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.0.1")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.SoapTypeAttribute(Namespace="https://XXX/account")]
public partial class CheckAddressSuccess
{
...
}
【问题讨论】:
标签: c# wcf asp.net-core soap client