Programing

WCF 오류- 'UserService.UserService'계약을 참조하는 기본 끝점 요소를 찾을 수 없습니다.

lottogame 2020. 8. 24. 20:53
반응형

WCF 오류- 'UserService.UserService'계약을 참조하는 기본 끝점 요소를 찾을 수 없습니다.


이 문제를 해결하는 방법에 대한 아이디어가 있습니까?

UserService.UserServiceClient userServiceClient = new UserServiceClient();
            userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted);
            userServiceClient.GetUsersAsync(searchString);

.

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_UserService" 
                     maxBufferSize="2147483647" 
                     maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:52185/UserService.svc" 
                  binding="basicHttpBinding" 
                  bindingConfiguration="BasicHttpBinding_UserService" 
                  contract="UserService.UserService"
                  name="BasicHttpBinding_UserService" />
    </client>
    <behaviors>
        <serviceBehaviors>
            <behavior name="Shell.Silverlight.Web.Service3Behavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
        <service behaviorConfiguration="Shell.Silverlight.Web.Service3Behavior" 
                 name="Shell.Silverlight.Web.Service3">
            <endpoint address="" 
                      binding="basicHttpBinding" 
                      contract="Shell.Silverlight.Web.Service3" />
            <endpoint address="mex" 
                      binding="mexHttpBinding" 
                      contract="IMetadataExchange" />
        </service>
    </services>
</system.serviceModel>

ServiceModel 클라이언트 구성 섹션에서 'UserService.UserService'계약을 참조하는 기본 끝점 요소를 찾을 수 없습니다. 이는 응용 프로그램에 대한 구성 파일이 없거나이 계약과 일치하는 끝점 요소가 클라이언트 요소에서 찾을 수 없기 때문일 수 있습니다.

해결되었습니다!

나는 이것이 Silverlight 응용 프로그램이라고 언급하지 않았습니다. 자체 "ServiceReferences.ClientConfig"파일이있는 DLL에 wcf 참조가 있습니다. DLL의 ServiceReferences.ClientConfig의 내용을 주요 silverlight 프로젝트로 옮겼습니다.


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.


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);

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.


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

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.


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


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

Your endpoints should specify an interface for the contract attribute:

contract="UserService.IUserService"

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


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


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.


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);

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);

In case if you are using WPF application using PRISM framework then configuration should exist in your start up project (i.e. in the project where your bootstrapper resides.)

In short just remove it from the class library and put into a start up project.

참고URL : https://stackoverflow.com/questions/699644/wcf-error-could-not-find-default-endpoint-element-that-references-contract-us

반응형