WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'

前端 未结 13 1765
野趣味
野趣味 2020-11-29 02:27

Any ideas how to fix this?

UserService.UserServiceClient userServiceClient = new UserServiceClient();
            userServiceClient.GetUsersCompleted += new          


        
相关标签:
13条回答
  • 2020-11-29 03:06

    Do you have an Interface that your "UserService" class implements.

    Your endpoints should specify an interface for the contract attribute:

    contract="UserService.IUserService"
    
    0 讨论(0)
  • 2020-11-29 03:06

    For those who work with AX 2012 AIF services and try to call there C# or VB project inside AX (x++) and suffer from such errors of "could not find default endpoint"... or "no contract found" ... go back to your visual studio (c#) project and add these lines before defining your service client, then deploy the project and restart AX client and retry: Note, the example is for NetTcp adapter, you could easily use any other adapter instead according to your need.

     Uri Address = new Uri("net.tcp://your-server:Port>/DynamicsAx/Services/your-port-name");
     NetTcpBinding Binding = new NetTcpBinding();
     EndpointAddress EndPointAddr = new EndpointAddress(Address);
     SalesOrderServiceClient Client = new SalesOrderServiceClient(Binding, EndPointAddr);
    
    0 讨论(0)
  • 2020-11-29 03:07

    You can also set these values programatically in the class library, this will avoid unnecessary movement of the config files across the library. The example code for simple BasciHttpBinding is -

    BasicHttpBinding basicHttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
    basicHttpbinding.Name = "BasicHttpBinding_YourName";
    basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
    basicHttpbinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
    
    EndpointAddress endpointAddress = new EndpointAddress("http://<Your machine>/Service1/Service1.svc");
    Service1Client proxyClient = new Service1Client(basicHttpbinding,endpointAddress);
    
    0 讨论(0)
  • 2020-11-29 03:09

    Not sure if it's really a problem, but I see you have the same name for your binding configuration ().

    I usually try to call my endpoints something like "UserServiceBasicHttp" or something similar (the "Binding" really doesn't have anything to do here), and I try to call my binding configurations something with "....Configuration", e.g. "UserServiceDefaultBinding", to avoid any potential name clashes.

    Marc

    0 讨论(0)
  • 2020-11-29 03:15

    Had to add the service in the calling App.config file to have it work. Make sure that you but it after all . This seemed to work for me.

    0 讨论(0)
  • 2020-11-29 03:17

    Not sure if this is an issue. Endpoint and binding both have the same name

    0 讨论(0)
提交回复
热议问题