简体   繁体   English

使用WCF时找不到引用合同例外的默认端点元素

[英]Could not find default endpoint element that references contract exception while using a WCF

I created a WCF which later on I converted to SSL(HTTPS) For which i made some changes in Web config. 我创建了一个WCF,后来我将其转换为SSL(HTTPS),为此我在Web配置中进行了一些更改。

I can browse this service and also getting the wsdl for the service. 我可以浏览该服务,也可以获取该服务的wsdl。

I am getting the proper response from service, when hit using HTTPWebrequest Class. 使用HTTPWebrequest类命中时,我从服务中获得了正确的响应。

Later i added this service as service Refrence with name NestleServiceRef. 后来我将此服务添加为服务Refrence,名称为NestleServiceRef。 While creating the object of this refrence using 在使用创建此引用的对象时

 NestleServiceRef.NestleMiddlewareClient nestle = new NestleServiceRef.NestleMiddlewareClient();

i am getting this exception: 我收到此异常:

System.InvalidOperationException: Could not find default endpoint element that references contract 'NestleServiceRef.INestleMiddleware' 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.
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
   at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
   at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
   at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
   at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
   at System.ServiceModel.ClientBase`1..ctor()
   at WebApplication1.NestleServiceRef.NestleMiddlewareClient..ctor() in C:\Users\461167\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Service References\NestleServiceRef\Reference.cs:line 221
   at WebApplication1._Default.Button2_Click(Object sender, EventArgs e) in C:\Users\461167\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Default.aspx.cs:line 29}

My Web.config file is : 我的Web.config文件是:

 <?xml version="1.0"?>
    <configuration>
      <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <section name="NestleMiddlewareWCF.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
      </configSections>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <membership>
          <providers>
            <clear />
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Clear" connectionStringName="SQLConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
          </providers>
        </membership>
      </system.web>
      <appSettings>
        <add key="sqliteTemplateName" value="D:\\NestleSQLite\\NestleSqliteTemplate.sqlite" />
        <add key="sqliteFileName" value="D:\\NestleSQLite\\NestleSqliteFile.sqlite" />
        <add key="sqliteConnection" value="Data Source=D:\NestleSQLite\NestleSqliteFile.sqlite;Version=3;New=false;Compress=True" />
        <add key="masterSqliteConnection" value="Data Source=D:\NestleSQLite\NestleSqliteTemplate.sqlite;Version=3;New=false;Compress=True" />
      </appSettings>
      <connectionStrings>
        <add name="SQLConnectionString" connectionString="server=01HW361477;user id=sa;password=DBP@ss;database=IK" />
        <add name="SQLConnectionString1" connectionString="server=01HW361477;user id=sa;password=DBP@ss;database=IK" />
      </connectionStrings>
      <system.serviceModel>
        <services>
          <service name="NestleMiddlewareWCF.NestleMiddleware" behaviorConfiguration="ServiceBehaviour">
            <endpoint address="https://10.137.243.130:12345/NestleMiddleware.svc" binding="webHttpBinding" bindingConfiguration="webBinding" contract="NestleMiddlewareWCF.INestleMiddleware" behaviorConfiguration="web" />
          </service>
        </services>
          <bindings>
              <webHttpBinding>
                  <binding name="webBinding">
                      <security mode="Transport">       </security>
                  </binding>
              </webHttpBinding>
          </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehaviour">

              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpsGetEnabled="true" httpsGetUrl="https://10.137.243.130:12345/NestleMiddleware.svc/mex" />
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="web">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>
      <applicationSettings>
        <NestleMiddlewareWCF.Properties.Settings>
          <setting name="NestleMiddlewareWCF_CopyService_Copy" serializeAs="String">
            <value>http://01hw361477:4880/_vti_bin/copy.asmx</value>
          </setting>
        </NestleMiddlewareWCF.Properties.Settings>
      </applicationSettings>
    </configuration>

您需要共享客户端配置文件的这一部分,该错误在那里报告,并且上面的web.config似乎是服务主机的配置(或者它没有客户端部分,这就是问题所在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM