2010-09-28 7 views
3

J'apprends WCF et je suis maintenant en obtenir une exception lors de l'exécution de l'application: Exception:Raison de cette exception dans WCF

Impossible de trouver l'élément point final par défaut ce contrat références « IService1 » en la section de configuration du client ServiceModel . Cela peut être car aucun fichier de configuration n'a été trouvé pour votre application ou aucun élément de point de terminaison correspondant à ce contrat n'a pu être trouvé dans l'élément client .

Code de service:

namespace StockService 
{ 
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. 
    public class Service1 : IService1 
    { 
     public string GetData(int value) 
     { 
      return string.Format("You entered: {0}", value); 
     } 

     public CompositeType GetDataUsingDataContract(CompositeType composite) 
     { 
      if (composite == null) 
      { 
       throw new ArgumentNullException("composite"); 
      } 

      if (composite.BoolValue) 
      { 
       composite.StringValue += "Suffix"; 
      } 

      return composite; 
     } 

     public string GetCompositedata() 
     { 
      CompositeType ct = new CompositeType(); 
      return ct.StringValue; 
     } 
    } 
} 

web.config:

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
      <serviceMetadata httpGetEnabled="true"/> 
      <!-- 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> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

maintenant avec svcutil je généré proxyclass (generatedProxy.cs) et le fichier de configuration (serviceapp.config) et l'a ajouté à une application de console (client)

Client:

Service1Client sc = new Service1Client(); 
Console.WriteLine(sc.GetCompositedata()); 
Console.ReadKey(); 

config:

<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="BasicHttpBinding_IService1" 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="None"> 
         <transport clientCredentialType="None" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="UserName" algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:2614/Service1.svc" binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IService1" contract="IService1" 
       name="BasicHttpBinding_IService1" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

Je ne suis pas en mesure de comprendre pourquoi je reçois cette exception.

S'il vous plaît aider

Répondre

6

Cette configuration est-elle affichée pour la partie client de l'application client app.config ou web.config, s'il s'agit d'un site Web/d'une application Web?

Vous devez inclure ces parties dans la configuration de votre application - il ne suffit pas d'avoir ces config dans un fichier séparé créé par svcutil.exe - il doit faire partie de la configuration de votre application.

+0

c'est une application console (client) – Wondering

+1

ok, fonctionnant maintenant, a ajouté un app.config dans l'application console et a ajouté le code (généré à partir de svcutil) à ce fichier, il fonctionne maintenant.Merci. – Wondering

2

La configuration doit aller dans votre principale app.config généré svcutil, ne pas être inclus en l'état.

Vous devez ajouter un app.config à votre projet, puis fusionner le contenu de la configuration svcutil dans la section de configuration.

+0

Merci Rup, votre sln aidé. – Wondering

Questions connexes