1

I am working on ASP.NET WCF simple HelloWorld Example. I have successfully completed server side but I am getting issue while working on client side. I have used SVCUTIL.exe to generate proxy classes for me.

On debug I am getting following error;

An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code

Additional information: Could not find endpoint element with name    'WSHttpBinding_IHelloWorldService' and contract 'IHelloWorldService' 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.

another thing, can I use Channel Factory if I don't access to dll file from server, say If I got access to WSDL url link

On Client Side app.config

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IHelloWorldService" />
            <binding name="WSHttpBinding_IHelloWorldServiceAsyn" />
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:8087/CreditUnionServices/HelloWorldServices/HelloWorldService"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloWorldService"
            contract="IHelloWorldService" name="WSHttpBinding_IHelloWorldService">
            <identity>
                <userPrincipalName value="DESKTOP-G6LE8I4\Khurram Zahid" />
            </identity>
        </endpoint>
        <endpoint address="http://localhost:8087/CreditUnionServices/HelloWorldServices/HelloWorldServiceAsyn"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloWorldServiceAsyn"
            contract="IHelloWorldServiceAsyn" name="WSHttpBinding_IHelloWorldServiceAsyn">
            <identity>
                <userPrincipalName value="xyz\abc" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

Client Proxy Channel Factory

 public class HelloWorldClient
{
    public string SendTestMessage(string name)
    {
        ChannelFactory<IHelloWorldService> _HelloWorldClientService = new ChannelFactory<IHelloWorldService>("WSHttpBinding_IHelloWorldService");

        IHelloWorldService _HelloWorldChannelService = _HelloWorldClientService.CreateChannel();

        var _returnMessage = _HelloWorldChannelService.GetMessage(name);

        ((IClientChannel)_HelloWorldChannelService).Close();

        return _returnMessage;
    }
}

Server side config file

 <system.serviceModel>
<services>
  <service name="App.Services.Managers.HelloWorldManager" behaviorConfiguration="DefaultServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8087/CreditUnionServices/HelloWorldServices"/>
      </baseAddresses>
    </host>
    <endpoint address="HelloWorldService" binding="wsHttpBinding" contract="App.Services.Contracts.IHelloWorldService"></endpoint>
    <endpoint address="HelloWorldServiceAsyn" binding="wsHttpBinding" contract="App.Services.Contracts.IHelloWorldServiceAsyn"></endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="DefaultServiceBehavior">
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Update Code

public static class HelloWorldClient 
{
    public static string SendTestMessage(string name)
    {

        HelloWorldServiceClient _helloWorldService = new HelloWorldServiceClient("WSHttpBinding_IHelloWorldService");

        var _returnMessage =  _helloWorldService.GetMessage("mr kz ....");

        return _returnMessage;
    }
}
K.Z
  • 5,201
  • 25
  • 104
  • 240
  • proxies are different than channel factory. To use a channel factory pattern, you need to have direct access over the service contract i.e. the assembly defining the service. Mostly when the service is directly bound to the client. Try to build the connection as simple method calls using the proxy class object. – Amit Kumar Ghosh Jun 10 '16 at 12:30
  • I am update my code as above in my question at bottom , but still getting same error – K.Z Jun 10 '16 at 13:47
  • I have test this code in separate application and it work but for reason not working in my main application – K.Z Jun 10 '16 at 14:13

0 Answers0