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

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

Any ideas how to fix this?

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


        
相关标签:
13条回答
  • 2020-11-29 02:57

    Just in case anyone hits the same problem whilst using WPF (rather than WCF or Silverlight):

    I had this error, when connecting to a Web Service. When my code was in the "main" WPF Application solution, no problem, it worked perfectly. But when I moved the code to the more sensible DAL-layer solution, it would throw the exception.

    Could not find default endpoint element that references contract 'MyWebService.MyServiceSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

    As has been stated by "Sprite" in this thread, you need to manually copy the tag.

    For WPF apps, this means copying the tag from the app.config in my DAL solution to the app.config in the main WPF Application solution.

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

    Rename the output.config produced by svcutil.exe to app.config. it worked for me.

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

    I ran into the same issue, for whatever reason Visual Studio did not update the web config when I first added the service. I found that updating the Service Reference also fixed this issue.

    Steps:

    1. Navigate to the Service Reference Folder
    2. Expand it
    3. Right Click and Select update Service Reference
    4. Observe web Config be updated
    0 讨论(0)
  • 2020-11-29 03:03

    This problem occures when you use your service via other application.If application has config file just add your service config information to this file. In my situation there wasn't any config file so I use this technique and it worked fine.Just store url address in application,read it and using BasicHttpBinding() method send it to service application as parameter.This is simple demonstration how I did it:

    Configuration config = new Configuration(dataRowSet[0]["ServiceUrl"].ToString());
    
    var remoteAddress = new System.ServiceModel.EndpointAddress(config.Url);
    
    
    SimpleService.PayPointSoapClient client = 
        new SimpleService.PayPointSoapClient(new System.ServiceModel.BasicHttpBinding(), 
        remoteAddress);
    SimpleService.AccountcredResponse response = client.AccountCred(request);
    
    0 讨论(0)
  • 2020-11-29 03:04

    I had a run in with the same problem. My application was also a Silverlight application and the service was being called from a class library with a custom UserControl that was being used in it.

    The solution is simple. Copy the endpoint definitions from the config file (e.g. ServiceReferences.ClientConfig) of the class library to the config file of the silverlight application. I know you'd expect it to work without having to do this, but apparently someone in Redmond had a vacation that day.

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

    Change the web.config of WCF service as "endpoint address="" binding="basicHttpBinding"..." (previously binding="wsHttpBinding")After build the app, in "ServiceReferences.ClientConfig" ""configuration> has the value. Then it will work fine.

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