Ошибка "Attribute contract is required on element endpoint" в приложении ASP.Net

Проблема: при попытке из программного кода ASP.Net обратиться с запросом к веб-сервису (asmx) возникает ошибка:
Server Error in '/' Application.

Attribute 'contract' is required on element 'endpoint'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Configuration.ConfigurationErrorsException: Attribute 'contract' is required on element 'endpoint'.

Source Error:  
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace: 

[ConfigurationErrorsException: Attribute 'contract' is required on element 'endpoint'.]
   System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) +812598
   System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) +814360
   System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +826826
   System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) +826826
   System.Configuration.BaseConfigurationRecord.GetSection(String configKey) +69
   System.Configuration.ConfigurationManager.GetSection(String sectionName) +140
   System.ServiceModel.Activation.AspNetEnvironment. UnsafeGetSectionFromConfigurationManager(String sectionPath) +42
   System.ServiceModel.Configuration.ConfigurationHelpers. UnsafeGetAssociatedSection(ContextInformation evalContext, String sectionPath) +40
   System.ServiceModel.Description.ConfigLoader.LookupChannel(ContextInformation configurationContext, String configurationName, ContractDescription contract, EndpointAddress address, Boolean wildcard, Boolean useChannelElementKind, ServiceEndpoint& serviceEndpoint) +141
   System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address) +133
   System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress) +409
   System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory() +16661296
   System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait) +27
   System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef() +546
   Account_Login.ViewQueryLogin() +924
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +12308266
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +12307881
   System.Web.UI.Page.ProcessRequest() +119
   System.Web.UI.Page.ProcessRequest(HttpContext context) +99
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.
IExecutionStep.Execute() +913
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212


Данная ошибка означает, что в файле web.config неверно задана ветка для обращения к веб-сервису <system.serviceModel><client><endpoint>. Откройте конфигурационный файл и проверьте, какие параметры заданы в указанной ветке. Пример:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="AuthServiceSoap" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" 
        sendTimeout="00:01:00" allowCookies="false" 
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
         maxBufferSize="65536" maxBufferPoolSize="524288" 
         maxReceivedMessageSize="65536" messageEncoding="Text" 
         textEncoding="utf-8" transferMode="Buffered" 
         useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" 
          maxArrayLength="16384" maxBytesPerRead="4096" 
          maxNameTableCharCount="16384" />
          <security mode="Transport">
            <transport clientCredentialType="None" 
            proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" 
            algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint 
      address="https://192.168.0.55:83/auth1/Services/AuthService.asmx" 
      binding="basicHttpBinding" bindingConfiguration="AuthServiceSoap" 
      contract="SSOAuthService.AuthServiceSoap" name="AuthServiceSoap" />
    </client>
  </system.serviceModel>

Обратите внимание на параметр "contract". Если возникает подобная ошибка, то данного параметра либо нет, либо он указан неверно. Он должен содержать название "контракта" по которому приложение будет взаимодействовать с указанным веб-сервисом. В коде самого приложения должен быть реализован данный тип контракта, например, в стандартной ASP-папке App_WebReferences (в виде файлов svcmap, disco, wsdl, svcinfo):



(с) Ella S.

Комментариев нет :

Отправить комментарий