2
votes

I have added wcf service in "Windows Service" as service reference. but when i try to create instance it simply gives me following error

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

Code

            pushNotification push_notification = new pushNotification();
            var proxy = new ServiceReference1.ClientServiceClient();

            using (var scope = new OperationContextScope(proxy.InnerChannel))
            {
                // Add a HTTP Header to an outgoing request

                HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                requestMessage.Headers["Authorization"] = "Push Notification";
                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
                push_notification = proxy.GetPendingNotification();
            }

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IService1" />
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:4567/ClientService.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IClientService"
        name="BasicHttpBinding_IService1"    behaviorConfiguration="webHttpBehavior" />
  </client>
<behaviors>
  <endpointBehaviors>
    <behavior name="webHttpBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
</system.serviceModel>

1
Well, have you setup a matching endpoint in your app.config file?Belogix
No. not really. i assume it should automatically pick that up as i have added it as reference.Hammad Nasir
can you please show your config file's ServiceModel section..Sachin
i have added binding and it seems to be working now.Hammad Nasir

1 Answers

1
votes

Be sure you put the endpoint information in your main App.config or Web.config. If you've added the service reference in a separate project you need to copy the config:

    <system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IService1" />
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:4567/ClientService.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IClientService"
        name="BasicHttpBinding_IService1" />
  </client>
</system.serviceModel>

In your startup project App.config/Web.config!