0

I've been working on a wrapper for an API that will let me access it via a web service. The wrapper is a WCF service that I'm using to interface between the API and an asmx.

API---WCF---Webservice

Currently, I can get the API to work with the wrapper and the wrapper to communicate with the web service. However, any calls I make that originate from the web service to the API fail. The line that causes the failure is one that accesses a registry key on the host. My guess is that this is somehow permission related, but I'm new to C# and web services so I don't know for sure. If it is permission related, where/how can I give the client permission to access the host's registry?

WFC code:

public class IRClass
{


...


    public string init()
    {
        string result = "THE SERVICE IS WORKING BORK BORK\n";
        int handle = 1234;
        double retVal = -1;       


    Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Rand McNally\DispatchAssistant\StandAlone\Install");
    \\^^^ THIS RETURNS NULL WHEN CALLED BY A CLIENT ^^^



        if (key != null)
        {

            string sbDARouterFilePath = key.GetValue("DaRouterPath").ToString();
            string sbDADataFilePath = key.GetValue("DaDataPath").ToString();
            string sbRouterFilePath = key.GetValue("RoutePath").ToString();
            string sbMapFilePath = key.GetValue("MapPath").ToString();
            string sbAdminFilePath = key.GetValue("AdminPath").ToString();
            string sbDataFilePath = key.GetValue("DataPath").ToString();

            try
            {
                RECode = irLib.irSAInitialize(sbDARouterFilePath, sbDADataFilePath, sbRouterFilePath, sbMapFilePath, sbAdminFilePath, sbDataFilePath);
            }
            catch (Exception e)
            {

                throw new Exception("irSAInitialize call failed in IntelliRouteLib.IRApi\n + e.Message);

            }
            result += "Key: " + key.ToString() + " \n";
        }

    else
        {
            result += "KEY IS NULL\n"; \\THIS SHOULDN'T HAPPEN
        }



    ...



        return result;//return RECode.ToString();
    }
}

WCF App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="RmWcfServiceLibrary.RMService">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/RmWcfServiceLibrary/RMService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <endpoint address="" binding="basicHttpBinding" contract="RmWcfServiceLibrary.IIntRoute">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "SdrConfigExample.e2e" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

WebService Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using RMWebService.RmWcf;

namespace RMWebService
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string Intelliroute()
        {
            IntRouteClient client = new IntRouteClient();
            string output = client.IRinit();
            client.Close();
            return output;
        }
    }
}

Thanks

  • Does the machine hosting your WCF service have the specified key? See: https://msdn.microsoft.com/en-us/library/z9f66s0a(v=vs.110).aspx#Anchor_2 – Will Ray Apr 18 '16 at 21:50
  • It could be due to registry redirection, which basically means that registry key doesn't exist because windows redirects it automatically to a location that doesn't exist. Instead of using `Microsoft.Win32.Registry.LocalMachine.OpenSubKey`, you need to use the OpenBaseKey method. See [here](http://stackoverflow.com/questions/974038/reading-64bit-registry-from-a-32bit-application/13232372#13232372), and [here](http://stackoverflow.com/questions/15424205/reading-and-writing-to-x86-and-x64-registry-keys-from-the-same-application/15424697#15424697) for examples and more information. – Quantic Apr 18 '16 at 21:54
  • Thanks for the replies! What is really confusing me is why I get different behavior from calling the service remotely vs. from the solution. I thought that WCF services were all server side, so shouldn't it not matter where the function call comes from if the same code is executing? – Eric Winkler Apr 19 '16 at 14:05

0 Answers0