tags:

views:

950

answers:

4

I have a WCF service which is being hosted in IIS.I have a WCF client also (a console application) .I have used the svcutil to build the proxy class and configuration file and then added those to my client project.It builded properly.But when i tried to run the program,ITs throwing me the below exception

Could not find default endpoint element that references contract 'IService' 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.

//My client program code

 namespace MyFirstWCFClient
{
 class Program
 {
    static void Main(string[] args)
    {
        ServiceClient objClient = new ServiceClient();
        Console.WriteLine("Client calling the service....");

        string strName=Console.ReadLine();
        Console.WriteLine(objClient.HelloWorld("Shyju"));
        Console.Read();

    }
 }
}

Output.config file of my client is

  <?xml version="1.0" encoding="utf-8"?>
   <configuration>
    <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost/IISHostedserviceTest/Service.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
            contract="IService" name="WSHttpBinding_IService">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
     </client>
 </system.serviceModel>
</configuration>

and in the web.config of my service has the below configuration

   <system.serviceModel>
   <services>
    <service name="Service" behaviorConfiguration="ServiceBehavior">
    <!-- Service Endpoints -->
    <endpoint address="http://localhost/IISHostedserviceTest/Service.svc" binding="wsHttpBinding" contract="IService">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <!-- 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>
 </system.serviceModel>

I used this(http://www.wcftutorial.net/WCF-IIS-Hosting.aspx) tutorial to have a try on WCF.

Can anyone guide me how to resolve this ?

+1  A: 

You have to use the constructor for the client that specifies the endpoint configuration name, eg.

objClient = new ServiceClient ("WSHttpBinding_IService");

That will tell the proxy to use the configuration you specified in the config file.

axel_c
No Axel,The exception remains the same
Shyju
+2  A: 

Stupid question: if your client app is called myclient.exe, is your config in the same directory as the EXE and called MyClient.exe.config ?

You can't just take the output.config from svcutil - you need to either add a app.config to your client console project (which will be renamed to myclient.exe.config when compiling), or you need to copy/rename the output.config to myclient.exe.config in order for your client app to find and use it.

marc_s
+1  A: 

Another approach to take would be to add a Service Reference to your IIS hosted service. Visual Studio will automatically run svcutil in the background and do the configuration work for you - i.e. it'll create the app.config for you.

Doing it manually is fine, but I suggest running it at least once by adding a Service Reference just to see it work properly.

Terry Donaghe
A: 

my code on client side ---

class Program { static void Main(string[] args) { MyServiceClient.MyServiceClient client = new ConsoleApplication1.MyServiceClient.MyServiceClient("WSHttpBinding_IMyService");

        Console.WriteLine("Client calling the service...");
        Console.WriteLine(client.HelloWorld("Ram"));
        Console.Read();

    }
}

NOT ABLE TO RESOLE THE ABOVE PROBLEm