Custom Widget using WCF Server Reference

Posted by Community Admin on 04-Aug-2018 01:13

Custom Widget using WCF Server Reference

All Replies

Posted by Community Admin on 12-Nov-2012 00:00

I created a WCF Service to expose a database.  The service works fine and I was able to create a test client app that loads the server reference and calls it's functions.

I then tried to create a Web User Control to use as a Sitefinity custom widget.  I added the Server Reference to the control and then followed the usual process of adding the widget to Sitefinity.

When I drag the widget onto my template I get the following error:

c:\inetpub\wwwroot\mutual\App_Data\Sitefinity\WebSiteTemplates\Mutual\WidgetTemplates\AgentFinder\AgentFinderUserControl.ascx.cs(7): error CS0234: the type or namespace 'ServiceReference1' does not exist in the namespace 'SiteFinityAgentfinder' (are you missing an assembly reference?)

I've successfully added widgets before and my test client app is able to access the web service reference just fine. It's only when I try to do it through SiteFinity that it errors out.

 When you create a server reference it adds a binding and a client entry to the web.config. I tried putting the web.config in the widget folder but that didn't help. I also tried adding the entries to SiteFinity's web.config and that didn't work either.



Posted by Community Admin on 12-Nov-2012 00:00

Here is the source for the files.

Web.config

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  go.microsoft.com/.../
  -->

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IAgencyFinderService" 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="agentfinder/AgencyFinderService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAgencyFinderService"
                contract="ServiceReference1.IAgencyFinderService" name="BasicHttpBinding_IAgencyFinderService" />
        </client>
    </system.serviceModel>
</configuration>

AgentFinderUserControl.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SiteFinityAgentFinder.ServiceReference1;

namespace SiteFinityAgentFinder

    public partial class AgentFinderUserControl : System.Web.UI.UserControl
   
        protected void Page_Load(object sender, EventArgs e)
       
            AgencyFinderServiceClient afsc = new AgencyFinderServiceClient("BasicHttpBinding_IAgencyFinderService");
            Agency[] agencies = afsc.GetAgencyList(null);

            AgentHTMLLiteral.Text = "Agents Found: " + agencies.Count() + " Variables: " + Request.Form.Count;
       
   

AgentFinderUserControl.ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AgentFinderUserControl.ascx.cs" Inherits="SiteFinityAgentFinder.AgentFinderUserControl" %>

<asp:Literal ID="AgentHTMLLiteral" runat="server" />

This thread is closed