0

Possible Duplicate:
WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'

My client side code is the following:

public virtual bool CanExecute(Move movement)
        {
            using (MediatorServiceContractClient mediatorProxy = new MediatorServiceContractClient())
            {
                return mediatorProxy.CanMove(movement);
            }
        }

The error occurs at the constructor of MediatorServiceContractClient.

The contract is as follows:

namespace GameServices
{
    [ServiceContract]
    public interface IMediatorServiceContract
    {
        [OperationContract]
        bool CanMove(Move move);
    }
}

I have a GameServices library that has the following config data:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IMediatorServiceContract" 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" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8732/GameServices/Mediator/"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMediatorServiceContract"
          contract="GameViewModel.MediatorServiceReference.IMediatorServiceContract"
          name="WSHttpBinding_IMediatorServiceContract">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
    <services>
      <service name="GameServices.MediatorService">
        <endpoint address="" binding="wsHttpBinding" contract="GameServices.IMediatorServiceContract">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/GameServices/Mediator/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <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>
  </system.serviceModel>

</configuration>

I then have a ViewModel library that has the following config data:

enter code here`<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IMediatorServiceContract" 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" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8732/GameServices/Mediator/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMediatorServiceContract2"
                contract="GameViewModel.MediatorServiceReference.IMediatorServiceContract"
                name="WSHttpBinding_IMediatorServiceContract">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

I also receive the following error message at runtime: Could not find default endpoint element that references contract 'MediatorServiceReference.IMediatorServiceContract' 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.

I have viewed all the comments and feedback regarding this common issue. However for me the problem persists and I am stuck. What am I missing? Why is this so complicated?

Community
  • 1
  • 1
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
  • 1
    post the code that's using the service (i.e. the client). I'm guessing the first config file is for the service (but why does it have a client endpoint?) the second is for the client to connect. – Mark W Nov 30 '11 at 02:15
  • Yes. The first config data is server-side. The second post of config data is client-side. – Scott Nimrod Nov 30 '11 at 12:43
  • The client endpoint was auto-generated on the server-side config file. – Scott Nimrod Nov 30 '11 at 12:53

3 Answers3

1

Looks like the contract in the endpoint of the client side config should be GameServices.IMediatorServiceContract and not GameViewModel.MediatorServiceReference.IMediatorServiceContract, assuming the code of the interface you pasted above is what the client actually uses.

Mark W
  • 3,879
  • 2
  • 37
  • 53
  • I updated the client-side config with just GameServices.IMediatorServiceContract. However, I am still receiving the same error. I would be happy to send you the source code... – Scott Nimrod Nov 30 '11 at 22:43
  • I'm still stuck. I sincerely think this is a bug in VS2010. I also watched and redid the configuring of the client. I watched the following video: http://channel9.msdn.com/shows/Endpoint/Endpoint-Screencasts-Creating-Your-First-WCF-Client/ – Scott Nimrod Dec 01 '11 at 23:10
0

A couple of things (I've not worked with WPF, but I've done a lot with WCF, so if it's a WPF-specific issue this may not apply).

The error message you're seeing says it cannot find an endpoint for MediatorServiceReference.IMediatorServiceContract. If you look at the service config, your endpoint contract is GameServices.IMediatorServiceContract; most likely this is the cause for the error. Fix the contract referenced and you should be good to go.

Secondly, it's considered bad practice to use the using block with proxies. It's better to simply open the proxy, make the call, and the close (or abort, as needed) the channel. See Avoiding Problems with the Using Statement for a detailed explanation.

Tim
  • 28,212
  • 8
  • 63
  • 76
  • Hi Tim, I updated the client-side to be GameServices.IMediatorServiceContract. However, I still receive the same error. I would be more than happy to send you the source code... – Scott Nimrod Nov 30 '11 at 22:47
0

Mike Gledhill was right for WPF apps. My source app config file was not in the in the client executable project but was in my viewmodel project (still on the client-side).

As a result I simply added a link to my app config within my viewmodel project from my executable project.

It finally worked after probably 12 hours of frustration.

So mental note: THE EXECUTABLE PROJECT MUST HAVE AN APP CONFIG FILE REFERENCED even if it does not contain the cs file performing the call.

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118