Search code examples
c#wcfasp.net-core.net-core

ASP Core "There was no endpoint listening at [url] that could accept the message. "


I have ASP core application which using WCF service.

Eg:

ServiceClient client = new ServiceClient();
client.SomeMetod();

I have new computer (old was win 7, new win 10).

I have exactly same project which was working, but now I get this error:

There was no endpoint listening at http://10.xxx.xxx.xxx:12345/Service.svc that could accept the message. This is often caused by an incorrect address or SOAP action

When I try to access service trough browser -- > OK When I try to run app on old computer --> OK When I try to run app on computer where is WCF hosted (so its on localhost, also win 10) --> OK

What could cause problem? Operation system, firewall, McAffee.. ?

I saw lot of pots here on stackoverflow, lot of them was editing some binding in web.config but I don't have web.config (If i understand it well web.config is generated when asp core projected is published)

Thank you for every idea...

EDIT 1 - Added generated Reference.cs file

namespace MesWCF { using 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,
    }
}
}

Solution

  • Finally I found a sollution.

    I find out, that I am able to use service from home through VPN. So I searched some problem where are people able to access through VPN.

    It was problem with proxy - This post helped me fix problem.

    According to mconnew's answer:

    HttpClient in .Net Core doesn't use WinINet which picks up its proxy settings from the same place as you configure IE/Edge proxy settings. It uses WinHTTP instead which maintains its own proxy settings. From an administrative command prompt execute the command netsh winhttp reset proxy to reset WinHTTP to use direct connections instead. If you want to see what it's currently set as, execute the command netsh winhttp show proxy before you modify it. It looks like your IT department probably missed resetting this configuration when getting rid of the proxy.

    So I tried netsh winhttp show proxy on both computers.

    New computer had some reccords about proxy and old none. Then I tried netsh winhttp reset proxy then i had same WinHTTP proxy settings as old computer.

    Then I was able to use WCF service :-)

    enter image description here