【发布时间】:2023-03-05 07:04:01
【问题描述】:
我做错了,我想不通...我制作了 .NET Framework 4 控制台应用程序来与 SOAP 服务进行通信,使用 Topshelf 我在服务器上部署了服务,并通过简单的 URL 访问方法或使用 Boomerang 工具,我可以看到服务正在返回值
网址:http://35.231.17.237:8066/ERPCommunicationService/OriginalService/IsServiceHealthy
但是现在,当我尝试从 .NET Core 项目访问相同的服务时,我不断收到错误消息:
System.ServiceModel.ProtocolException:
The remote server returned an unexpected response: (405) Method Not Allowed.
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(
SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(
String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.
<CreateGenericTask>b__0(IAsyncResult asyncResult)
--- End of stack trace from previous location where exception was thrown ---
代码很简单,我成功使用服务端点将它连接到.NET Core项目,在那里我可以看到Reference.cs自动生成的文件和来自服务的所有方法......
这是来自客户端(.net 核心)的服务调用:
public async Task<bool> IsServiceHealthy()
{
try
{
string servicesUrl = $"{_iConfiguration["servicesUrl"]}/IsServiceHealthy";
//My binding setup, since ASP.NET Core apps don't use a web.config file
var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.MaxReceivedMessageSize = 10485760;
binding.SendTimeout = new TimeSpan(0, 0, 0, 180);
binding.ReceiveTimeout = new TimeSpan(0, 0, 0, 180);
var rsExec = new OriginalService.OriginalServiceClient(binding,
new EndpointAddress(servicesUrl));
var clientFactory = rsExec.ChannelFactory.CreateChannel();
var response = await clientFactory.IsServiceHealthyAsync();
return response;
}
catch (Exception ex)
{
logging.LogError(ex.ToString());
throw ex;
}
}
以及来自服务器端的代码(.NET Framework 4):
界面:
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
UriTemplate = "/IsServiceHealthy")]
bool IsServiceHealthy();
实施:
public bool IsServiceHealthy()
{
bool serviceResult = false;
byte[] test = new byte[200];
var client = new ChannelFactory<BisWebWS.BisWebWSSOAPPortType>("BisWebWSSOAPPort")
.CreateChannel();
BisWebWS.tauthStrct auth = ServisBasic.GetAuth();
try
{
var result = client.wsTest(new BisWebWS.wsTestRequest(test));
serviceResult = result.wsTestResult;
}
catch (Exception ex)
{
logger.LogError(ex.InnerException.ToString());
}
return serviceResult;
}
每当我在谷歌上显示错误时,到处都是服务器端设置,但我有点卡住了,因为我安装了所有的东西......我使用的是 MS Windows Server 2012 R2 Datacenter,
感谢您分享如何解决此问题的想法
【问题讨论】: