1

I'm using USBHIDDRIVER to access a scale connected to our local workstation. Everything works fine when I run the WCF in Visual Studio 2012 Debug. But once I attempt to run the service in IIS it doesn't seem to recognize the USBHIDDRIVER. I have a test service in the WCF which works fine so the WCF is working.

Any information on how to troubleshoot this would be extremely helpful. My problem is that the WCF is compiled when I deploy to the IIS server so I'm having a hard time trying to troubleshoot.

Here is additional information regarding USBHIDDRIVER: http://www.florian-leitner.de/index.php/projects/usb-hid-driver-library/

namespace USBDevices
{    
    public class Service1 : IService1
    {
        public string GetWeight(string id)
        {
            USBHIDDRIVER.USBInterface usb = new USBHIDDRIVER.USBInterface("vid_0922","pid_8007"); 
            //string[] list = usb.getDeviceList();
            string result;
            string resultDesc;
            byte itemWeight;
            byte itemUOM;

            result = "";
            resultDesc = "";
            itemWeight = 0;
            itemUOM = 0;

            if (usb.Connect() == true)
            {
                usb.startRead();
                Thread.Sleep(100);
                for (int i = 0; i < 200; i++)
                {
                    var weight = USBHIDDRIVER.USBInterface.usbBuffer;
                    var cnt = weight.Count;
                    itemWeight = ((byte[])weight[cnt - 1])[4];
                    itemUOM = ((byte[])weight[cnt - 1])[2];
                }
                usb.stopRead();
                result = "Success";
                resultDesc = "Scale Found";
                Debug.WriteLine("Result: " + result + "-" + resultDesc + "  -  Item Weight: " + ((float)itemWeight / 10));
            }
            else
            {
                result = "Failed";
                resultDesc = "Scale Not Active";
                itemWeight = 0;
                itemUOM = 0;
                Debug.WriteLine("Result: " + result + "-" + resultDesc + "  -  Item Weight: " + ((float)itemWeight / 10));
            }

            return result + "|" + resultDesc + "|" + ((float)itemWeight / 10) + "|" + itemUOM;

        }

        public string XMLData(string id)
        {
            return "You requested product " + id;
        }

    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}
jrobinson6274
  • 163
  • 2
  • 13
  • IIS only supports local drives and UNC paths. Any other file access methods such as mapped drives are not supported. I believe you simply hit the limitation. – Lex Li Jun 03 '15 at 02:30
  • Thanks for the info Lex, I'm not trying to access a harddrive or USB Drive, I'm attempting to access a USB Scale. Everything works fine in the VS Debugger which leads me to believe there may be a permission issue but I'm having a hard time trying to troubleshoot the problem. In addition, the VS Debugger and IIS8 reside on the same workstation. So after I run test I'm simply publishing the WCF to the C: drive and attempting to run from a website on IIS. Frustrating but I'm really looking forward to that Aha! moment when I realize it was a simple problem LOL – jrobinson6274 Jun 03 '15 at 11:15
  • 1
    It might be a permissions issue, try setting the user in IIS to the same as you use when debugging in Visual Studio (IIS > [Site] > Basic Settings > Connect as...) – apc Jun 05 '15 at 12:29
  • What @apc said. (cue: background music from HotFuzz) – code4life Jun 05 '15 at 13:08
  • Hi Apc, I made the modification but got the same result. Scale not active. which means the USBHIDDRIVER.USBInterface is not communicating with the scale. – jrobinson6274 Jun 05 '15 at 13:54
  • I'm thinking about setting up the WCF as a Windows Service but I'm not sure if I will run into the same issue. – jrobinson6274 Jun 05 '15 at 13:57
  • Was just about to suggest a Windows Service hosted WCF service myself to act as middle man between ASP/IIS and the USB device. – apc Jun 05 '15 at 14:34
  • @APC Thanks for your help, it set me on the path which helped me determine that I needed to reference the 32 bit DLL's from IIS8 on my local workstation. This meant I had to turn on "Enable 32-Bit Applications" for my website. – jrobinson6274 Jun 05 '15 at 17:48

1 Answers1

0

In order to resolve the problem I had to turn on "Enable 32-Bit Applications" for the website. Believe the problem is related to the DLL's that are used but USBHIDDRIVER

jrobinson6274
  • 163
  • 2
  • 13