c# - 来自 .NET Core 应用程序的 SOAP Web 服务调用
问题描述
我目前有以下代码
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
namespace ProjectName.Services
{
[ServiceContract(Namespace = "http://domainName/WS")]
interface WS
{
[OperationContract()]
string GetChart(string id, bool Small, string ChartType);
}
public class ChartService : IChartService
{
public void GetChart()
{
var binding = new BasicHttpBinding();
var Uri = new Uri("http://siteUrl/ws/serviceName.asmx");
var endpoint = new EndpointAddress(Uri);
var channelFactory = new ChannelFactory<WS>(binding, endpoint);
var serviceClient = channelFactory.CreateChannel();
var result = serviceClient.GetChart("123456", true, "V");
channelFactory.Close();
}
}
}
哪个(我认为)正确调用了 Web 服务,但是,它抛出了以下异常:
"OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'GetChartResponse' and namespace 'http://domainName'.
Found node type 'Element' with name 'GetChartResponse' and namespace 'http://domainName/WS/'"
但是将 '/WS' 添加到命名空间(这是我尝试调用的服务的实际命名空间)会引发:
"System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://domainName/WS/WS/GetChart.\n
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()\n at System.Web.Services.Protocols.SoapServerProtocol.Initialize()\n
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)\n
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)"
如何设置预期的命名空间或使其不将接口名称添加到 SOAPAction 标头?
解决方案
推荐阅读
- c++ - 我的用于汇总数组元素的 C++ 代码无法正常工作
- python - 如何在 tf.keras 自定义损失函数中触发 python 函数?
- reactjs - 在安装包后导入包或在创建新的 React 应用程序时将其包含在 index.html 中有什么区别?
- javascript - 在 JavaScript 中打开和修改文件的函数
- xamarin - 如何在 xamarin 表单应用程序中正确实现 mapbox
- java - java.lang.UnsatisfiedLinkError 即使库和类有方法
- javascript - 返回第一个找到的值对象
- reactjs - 使用 history.push 进行呼叫转移
- python - tkinter 代码执行顺序问题
- c# - 调用泛型函数并分配泛型变量时编译错误