0

I am trying to consume a service in my module in the module web config I added my service config as the following.

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="WSEventSoap" />
    <binding name="BasicHttpBinding_ITwitterService" />
    <binding name="BasicHttpBinding_ILoyalty">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
</bindings>
<client>
    <endpoint name="BasicHttpBinding_ITwitterService"
        address="wwww.mysite.com/MediaServices/TwitterService.svc"   
        binding="basicHttpBinding" 
        bindingConfiguration="BasicHttpBinding_ITwitterService"  
        contract="TwitterService.ITwitterService" />
</client>
</system.serviceModel>

within the modules web.config. What I am noticing is that

  1. I can't seem to access web config settings in my module
  2. I keep getting the following error.

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

Please help.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1723409
  • 133
  • 1
  • 1
  • 7
  • Add it to the Orchard.Web web.config – Hazza May 11 '15 at 22:05
  • Well, the module's web.config won't help, and the global web.config is a common resource, so shouldn't be used, as it will prevent your module from being portable to another instance of Orchard without having to modify its web.config as well. The only clean solution I see is to query the service without this binding business. A web service is just using http, after all. – Bertrand Le Roy May 12 '15 at 06:28

1 Answers1

1

On the site I'm currently working on, like Betrand suggests, we've avoided modifying the global web.config to ensure the module is portable between projects.

Instead we've just created the Binding and Endpoint in code, rather that them getting pulled from the config. We've added our own setting to the Orchard site settings to let the user specify the endpoint address via the admin dashboard, which is the only part we actually need to be configurable.

To do this, in the module add a service reference as normal, if it adds those sections to your module web.config remove them as you won't be using them.

Then in code do something like

Binding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:8050/MyService/");

using (var client = new MyServiceClient(binding, endpointAddress))
{
    client.MyMethod();
}

There's plenty examples of this on Stackoverflow and elsewhere (e.g. WCF: How can I programatically recreate these App.config values?)

Community
  • 1
  • 1
Eddy Kavanagh
  • 254
  • 2
  • 15