Consume Webservice in a Orchard Module

Topics: Writing modules
Apr 16, 2013 at 4:46 PM
Hi,

I've got a problem to consume a webservice from an Orchard Module. Here what i did:

1) I created a projet for webservice called TaskME which work fine in the test projet, you can find it here: My webservice project (this use Entity Framework so need sqlserver, but you can look at the codes.). What i do is:
  • I start my webservice that launch IIS then i open my Orchard project
2) In Orchard, i created a module (A basic Orchard Hello module) and i just want to call my webservice and getting information. You can find my module here: My orchard module

Here what i do:
  • A add a new service reference of my webservice into the orchard module
  • This modify my module's web.config (near Routes.cs):
<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ITaskMEServiceInterface" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:49889/TaskMEService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITaskMEServiceInterface"
        contract="TaskMEServiceOrchard.ITaskMEServiceInterface" name="BasicHttpBinding_ITaskMEServiceInterface" />
    </client>

  </system.serviceModel>
  • Then i simply call my interface reference in my Orchard module:
           TaskMEServiceInterfaceClient taskme = new TaskMEServiceInterfaceClient();

            var model = taskme.GetClient(1);

            return View("COZ_1");
Here is the error message :

Unable to find an element of endpoint default refers to the contract 'TaskMEServiceOrchard.ITaskMEServiceInterface' in section ServiceModel client configuration. This may be due to the fact that the configuration file of your application is found or the endpoint element matching this contract is found in the client element.


Someone can help me?
Thanks :)
Apr 16, 2013 at 5:20 PM
i got it :)

I had to use a ChannelFactory at the place where i call my webservice (Controllers, or else) :
             BasicHttpBinding myBinding = new BasicHttpBinding();

            EndpointAddress myEndpoint = new EndpointAddress("http://localhost:49889/TaskMEService.svc");

            ChannelFactory<ITaskMEServiceInterface> myChannelFactory =
                new ChannelFactory<ITaskMEServiceInterface>(myBinding, myEndpoint);

            ITaskMEServiceInterface wcfClient1 = myChannelFactory.CreateChannel();

            ClientDTO clientDTO = wcfClient1.GetClient(1);