c# - ASP 核心“在 [url] 上没有可以接受消息的端点侦听。”
问题描述
我有使用 WCF 服务的 ASP 核心应用程序。
例如:
ServiceClient client = new ServiceClient();
client.SomeMetod();
我有新电脑(旧电脑是 win 7,新电脑是 win 10)。
我有完全相同的项目正在运行,但现在我收到此错误:
在 http://10.xxx.xxx.xxx:12345/Service.svc上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的
当我尝试通过浏览器访问服务时 --> OK 当我尝试在旧计算机上运行应用程序时 --> OK 当我尝试在托管 WCF 的计算机上运行应用程序时(所以它在 localhost 上,也是 win 10) -->好的
什么可能导致问题?操作系统、防火墙、McAffee.. ?
我在stackoverflow上看到了很多花盆,其中很多都在编辑web.config中的一些绑定,但我没有web.config(如果我理解得很好,web.config会在asp核心项目发布时生成)
谢谢你的每一个想法......
编辑 1 - 添加了生成的 Reference.cs 文件
命名空间 MesWCF { 使用 System.Runtime.Serialization;
// My classes here
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "MesWCF.IService")]
public interface IService
{
//My methods here - example bellow
//Example of one methods (collapsed above for brevity)
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService/GetUserAccount", ReplyAction = "http://tempuri.org/IService/GetUserAccountResponse")]
System.Threading.Tasks.Task<MesWCF.FraMesUser> GetUserAccountAsync(string name, string password);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
public interface IServiceChannel : MesWCF.IService, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.0")]
public partial class ServiceClient : System.ServiceModel.ClientBase<MesWCF.IService>, MesWCF.IService
{
/// <summary>
/// Implement this partial method to configure the service endpoint.
/// </summary>
/// <param name="serviceEndpoint">The endpoint to configure</param>
/// <param name="clientCredentials">The client credentials</param>
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
public ServiceClient() :
base(ServiceClient.GetDefaultBinding(), ServiceClient.GetDefaultEndpointAddress())
{
this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_IService.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public ServiceClient(EndpointConfiguration endpointConfiguration) :
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), ServiceClient.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public ServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public ServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
base(ServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
//Methods here
//Example of one method (collapsed above for brevity)
public System.Threading.Tasks.Task<MesWCF.FraMesUser> GetUserAccountAsync(string name, string password)
{
return base.Channel.GetUserAccountAsync(name, password);
}
public virtual System.Threading.Tasks.Task OpenAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}
public virtual System.Threading.Tasks.Task CloseAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
}
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IService))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IService))
{
return new System.ServiceModel.EndpointAddress("http://10.208.132.246:12345/Service.svc");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
{
return ServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_IService);
}
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
{
return ServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_IService);
}
public enum EndpointConfiguration
{
BasicHttpBinding_IService,
}
}
}
解决方案
也许这可以帮助你:
1 - 为 WCF ( step 6, If IIS does not open and gives any error, then you have to first enable IIS from Windows features. For this, follow the below steps
) 正确配置 IIS:
https://www.c-sharpcorner.com/article/hosting-wcf-service-on-iis/
2 - 为 WCF 启用 Windows 功能: