This project is read-only.

Module Web service settings

Topics: General, Writing modules
Apr 6, 2011 at 9:53 AM

What is the desired method for storing service reference settings i.e, the bindings, endpoints, behavious that are usualy stored in the web.config?

I currently have to the settings in the main web.config which is not idea for a module.

Apr 6, 2011 at 10:59 AM
Edited Apr 6, 2011 at 11:01 AM

Preferred method is to use an MVC controller to emit your services as actions. I assume you're talking about WCF ... when I tried that once for a particular purpose I found it unneccessarily complex, not to mention extremely limiting as any given service could only have 1 endpoint. You couldn't for instance have the same service responding to multiple different domains, because you had to explicitly set the domain name in the endpoint. Trying to add multiple endpoints just threw an exception. At that time the WCF guys said they had no intention of ever allowing such usage (I don't know if anything's changed since then) so I just went back to good ol' ashx services.

MVC actions are loads easier and if the default bindings don't work it's highly extensible.

Apr 6, 2011 at 1:06 PM

Thanks thats good advice, but I was actually referring to the storing of the settings for consuming web services?

Apr 6, 2011 at 3:31 PM
Edited Apr 6, 2011 at 3:33 PM

A quick google search results in many interesting discussions on the subject, some of which may or may not be helpful here.

WCF's requirement to expose bindings and configuration only thru Web.config is a serious limitation in and of itself and if you want to do things the MVC way you should consider building a RESTful controller instead, and forget service references - as some of those discussions point towards.

I think if this is the only way you can do things, you need to implement your service as a self-contained application which can be deployed independently of Orchard on the webserver, and then implement the repository pattern in Orchard to communicate with your webservice and expose that data in your controllers and so forth.

Which is why I didn't go any further with WCF; it makes things extremely complicated for what was for me a minimal perceived gain.

Apr 6, 2011 at 4:03 PM

I don't think I have described what I'm trying to acheive very well,

I have created a module that uses a webservice from a 3rd party that I have no control over e.g. Amazon

The Module is the Client of the service, to connect to the web service I need to add the following to the web.config of the Orchard.Web project

        <binding name="WSHttpBinding_IParticipant" 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="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false" 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" />
      <endpoint address="http://xxxxxxx.xxxxx.xxxx/xxxxx.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IParticipant" contract="ParticipantService.IParticipant" name="WSHttpBinding_IParticipant">
          <dns value="localhost" />
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />

This is not ideal as the Module need to portable, how can I package/keep the above settings in the Module's project?



Apr 6, 2011 at 4:16 PM

I understand exactly what you're trying to achieve; and Web.config configuration is simply not possible in an Orchard module. The modules are just MVC areas and not separate web applications, and their Web.config has no effect on the application root Web.config which is where you need your WCF service bindings.

So it's just not possible to distribute a WCF service within an Orchard module in this fashion. It has to be a wrapped up in a separately implemented and deployed application which your module can then talk with all it likes for its data repository implementation. But this requires additional installation steps by your end users and possibly unsupported server configuration on their part.

Do Amazon not provide any other service implementations that are more suited to the MVC pattern?

Apr 6, 2011 at 4:37 PM

Right ... I only just realised you are talking about the module being the Client (sorry). But, it's actually still the same problem, in that you have no ability to control the Web.config of the application. Does WCF even have a way to bind such a service manually with settings not from Web.config? If so then you can just store settings in the global Orchard site settings. Piotr Szmyd wrote a nice article here:

I'm still pretty sure that Amazon have APIs other than WCF service that might be vastly easier to configure :)