25

I have the following config for my WCF service:

<system.serviceModel>
<services>
  <service behaviorConfiguration="After.BehaviourConfig" name="ServiceInstancingDemo.Service1">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="After.BindingConfig"
      name="After.ConfigName" contract="ServiceInstancingDemo.IService1">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://rb-t510/NGCInstancing/Service1.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="After.BindingConfig" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferPoolSize="524288111" maxReceivedMessageSize="524288111" allowCookies="false">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="After.BehaviourConfig">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="30" maxConcurrentInstances="2147483647" maxConcurrentSessions="30" />
    </behavior>
  </serviceBehaviors>
</behaviors>

I am able to call the service with the following client code:

NGC.Service1Client ngc = new NGC.Service1Client();

        var taskA = Task<string>.Factory.StartNew(() => ngc.WaitThenReturnString(5));

        this.listBox1.Items.Add(taskA.Result);

The config for the client that calls the service is as follows:

 <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="Before" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferPoolSize="524288111"
                maxReceivedMessageSize="524288111" allowCookies="false" />
            <binding name="After" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" maxBufferPoolSize="524288111"
                maxReceivedMessageSize="524288111" allowCookies="false">
                <security mode="None" />
            </binding>
            <binding name="WSHttpBinding_IService1" 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="None">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://rb-t510/NGCInstancing/Service1.svc"
            binding="wsHttpBinding" bindingConfiguration="Before" contract="NGCInstance.IService1"
            name="Before" />
        <endpoint address="http://rb-t510/NGCInstancing/Service1.svc"
            binding="wsHttpBinding" bindingConfiguration="After" contract="NGCInstance.IService1"
            name="After" />
        <endpoint address="http://rb-t510/NGCInstancing/Service1.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
            contract="NGC.IService1" name="WSHttpBinding_IService1">
            <identity>
                <dns value="localhost" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

Problem is, I want to add another endpoint that will execute the same functionality but with a different behavior. To do this, I think I'm going to need to pass a string of the enpointConfigurationName to the constructor in the line=new NGC.Service1Client. I don't know what string I need to pass - I would have expected it to be the endpoint configuration name "After.ConfigName" but I tried this and got the following error message:

Could not find endpoint element with name 'After.ConfigName' and contract 'NGC.IService1' 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 name could be found in the client element.

Can anyone please help?

1 Answer 1

35

You would pass the value of the name attribute of the corresponding client endpoint you would like to use. For example if you wanted to use the third endpoint:

new NGC.Service1Client("WSHttpBinding_IService1")
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.