SharePoint Dragons

Nikander & Margriet on SharePoint

Tag Archives: wcf

Accessing a WCF service that is SharePoint context aware using the WCF channel factory

As discussed in forum thread http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/42f01511-3083-4d19-9058-00cf56af0fb7 , this is in fact an elegant way to reference a WCF service in the context of a given SharePoint web site without needing to change the web.config file of the SharePoint web application (this minimizing the overhead of managing custom software):

//Access WCF service Centre Detail Endpoint

WSHttpBinding binding = new WSHttpBinding();

EndpointAddress address = new EndpointAddress(SPContext.Current.Web.Url + “/_vti_bin/MyService/MyService.svc”);

ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, address); IGetCentreNames client = factory.CreateChannel();

Advertisements

Monitoring WCF services via AppFabric – note to self

Finally, after a bit of head slamming and crying: “why does this simple WCF service keeps having an empty WCF call history?” we found the answer.

First, we studied the web.config file of the service:

<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>

  <system.web>
    <compilation debug=”true” />
    <customErrors mode=”Off” />
  </system.web>

  <system.serviceModel>

<services>
   <service name=”NikWasService.Service1″ behaviorConfiguration=”BC”>
     <endpoint address=”” binding=”wsHttpBinding” contract=”NikWasService.IService1″ />

     <endpoint address=”mex” binding=”mexHttpBinding” name=”mexHttpEndpoint” contract=”IMetadataExchange” />

   </service>
</services>

  <behaviors>
    <serviceBehaviors>
      <behavior name=”BC”>
        <serviceMetadata httpGetEnabled=”true” />
        <serviceDebug includeExceptionDetailInFaults=”true” />
      </behavior>
                <behavior name=””>
                    <serviceMetadata httpGetEnabled=”true” />
                    <etwTracking profileName=”Troubleshooting Tracking Profile” />
                </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled=”true” />
        <diagnostics etwProviderId=”435613c0-3c9f-4a1e-aafe-7a314fbd9b0a”>
            <endToEndTracing propagateActivity=”true” messageFlowTracing=”true” />
        </diagnostics>
 
</system.serviceModel>

    <microsoft.applicationServer>
        <monitoring>
            <default enabled=”true” connectionStringName=”ApplicationServerMonitoringConnectionString” monitoringLevel=”Troubleshooting” />
        </monitoring>
    </microsoft.applicationServer>
 
</configuration>

Nothing wrong with that in particular. Double-checked that monitoring was enabled in the config file. We invoked the WCF service using the WCF Test Client. Nothing… Waited 10 seconds and tried again… Still nothing. Then, it hit us: the AppFabric Event Collection Service and Windows Event Collector services weren’t started. If nothing else, this is a note to self to insure we won’t make this mistake again!