WANTED: service.invokeaction in VB.NET 2010

Jan 26, 2012 at 2:08 AM

 

The C Code:
 
 {
     // Add the port mapping
     object[] loObj = new object[] { "", 29679, "UDP", 29679, "192.168.0.24", true, "Custom Mapping", 0 };
     lsService.InvokeAction("AddPortMapping", loObj);

     // Remove the port mapping
     loObj = new object[] { "", 29679, "UDP" };
     lsService.InvokeAction("DeletePortMapping", loObj);
 }



>> >> >> >> Opening port 45000 using service: DANCEHALL => WANIPConnection:1 on WAN Connection Device on UDP >> >> Service is: urn:upnp-org:serviceId:WANIPConn1 (urn:schemas-upnp-org:service:WANIPConnection:1) >> THE SUB CALLS: Dim loObj() As Object = { '', Port, Protocol.ToString, Port , lsHost , True , MappingName , 0} >> EXAMPLE: Dim loObj() As Object = { '', 29679, 'UDP' or 'TCP' , 29679 , localip eg:''192.168.0.24'' , True , ''Custom Mapping'' , 0} >> ACTUAL: Dim loObj() As Object = { '', 45000, ''UDP'' , 45000 ,''192.168.1.13'' , True , ''DUST SERVER at 7:29 PM'', 0} >> >> ERROR: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS >> DETAILS: ManagedUPnP.UPnPException: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS ---> System.Runtime.InteropServices.COMException: A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208 ) at UPNPLib.IUPnPService.InvokeAction(String bstrActionName, Object vInActionArgs, Object& pvOutActionArgs) at ManagedUPnP.Service.InvokeAction(String name, Object[] inParams) --- End of inner exception stack trace --- at ManagedUPnP.Service.InvokeAction(String name, Object[] inParams) at DustServer.Server_ManagedUPNP.OpenPort(String MappingName, Int32 Port, Protocol Protocol) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\Server_ManagedUPNP.vb:line 232 >> >>

 

 

 

Tried in VB.NET and the errors that followed:

 


 

 

 

  Dim loObj(0 To 7) As Object
            loObj(0) = ""
            loObj(1) = Port
            loObj(2) = Protocol.ToString
            loObj(3) = lsHost
            loObj(4) = True
            loObj(5) = MappingName
            loObj(6) = 0
 lsService.InvokeAction("AddPortMapping", loObj)

 >>
 >> ERROR: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS
 >> DETAILS: ManagedUPnP.UPnPException: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS ---> System.Runtime.InteropServices.COMException: A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208
)

 Dim loObj As Object = {"", Port, Protocol.ToString, Port, lsHost, True, MappingName, 0}
  lsService.InvokeAction("AddPortMapping", loObj)

 >> ERROR: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS
 >> DETAILS: ManagedUPnP.UPnPException: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS ---> System.Runtime.InteropServices.COMException: A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208
)
   at UPNPLib.IUPnPService.InvokeAction(String bstrActionName, Object vInActionArgs, Object& pvOutActionArgs)
   at ManagedUPnP.Service.InvokeAction(String name, Object[] inParams)
   --- End of inner exception stack trace ---
 

 Dim loObj() As Object = {"", Port, Protocol.ToString, Port, lsHost, True, MappingName, 0}
 lsService.InvokeAction("AddPortMapping", loObj)

 

 >> ERROR: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS
 >> DETAILS: ManagedUPnP.UPnPException: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS ---> System.Runtime.InteropServices.COMException: A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208
)
   at UPNPLib.IUPnPService.InvokeAction(String bstrActionName, Object vInActionArgs, Object& pvOutActionArgs)
   at ManagedUPnP.Service.InvokeAction(String name, Object[] inParams)
   --- End of inner exception stack trace ---

 


            Dim loObj As New Object()
            loObj(0) = ""
            loObj(1) = Port
            loObj(2) = Protocol.ToString
            loObj(3) = Port
            loObj(4) = lsHost
            loObj(5) = True
            loObj(6) = MappingName
            loObj(7) = 0

            lsService.InvokeAction("AddPortMapping", loObj)

 >> ERROR: No default member found for type 'Object'.
 >> DETAILS: System.MissingMemberException: No default member found for type 'Object'.
   at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, Boolean ReportErrors)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateIndexSetComplex(Object Instance, Object[] Arguments, String[] ArgumentNames, Boolean OptimisticSet, Boolean RValueBase)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateIndexSet(Object Instance, Object[] Arguments, String[] ArgumentNames)
   at DustServer.Server_ManagedUPNP.OpenPort(String MappingName, Int32 Port, Protocol Protocol) in E:\Program Files\Microsoft Visual Studio 10.0\My Documents\Projects\DUST\DustServer\Server_ManagedUPNP.vb:line 167


   Private Structure SampleObject
            Dim A As String
            Dim B As Integer
            Dim C As String
            Dim D As String
            Dim E As Boolean
            Dim F As String
            Dim G As Integer
            End Structure
    Dim loObj As SampleObject
            With loObj
                .A = ""
                .B = Port
                .C = Protocol.ToString
                .D = lsHost
                .E = True
                .F = MappingName
                .G = 0
            End With

   lsService.InvokeAction("AddPortMapping", loObj)

 >> ERROR: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS
 >> DETAILS: ManagedUPnP.UPnPException: UPnP Error #-2147220984: UPNP_E_INVALID_ARGUMENTS ---> System.Runtime.InteropServices.COMException: A user-supplied component or subscriber raised an exception (Exception from HRESULT: 0x80040208
)
   at UPNPLib.IUPnPService.InvokeAction(String bstrActionName, Object vInActionArgs, Object& pvOutActionArgs)
   at ManagedUPnP.Service.InvokeAction(String name, Object[] inParams)
   --- End of inner exception stack trace ---


If anyone can figure it out then let me know.

Coordinator
Jan 26, 2012 at 2:28 AM

vburgess,

These errors you are getting are coming from the UPnP device itself, different devices have different requirements sometimes, although I cannot see anything directly wrong with the parameters, you will need to play around with them to find out what is the cause, first of all check your router and make sure there isnt already a route setup for those ports, the service description for the WANPPPConnection interface can be found here:

http://www.upnp.org/specs/gw/UPnP-gw-WANPPPConnection-v1-Service.pdf

 

On page 33 you will find the documentation for the AddPortMapping action, have a read of this documentation and check to make sure there is nothing that may be causing the error.

Another thing to check is the data types of your variables ensure they are the right data types, the port should be an Int32, also try a value for the lease duration, maybe your device does not support infinite mapping durations.

Finally, try these exact values using the ManagedUPnP Test application and make sure it returns the same error you are getting, this will rules out any problems with the VB side of things (which I doubt is your problem anyway, but its good to check).

Let me know how you go.

Jan 26, 2012 at 3:19 AM

As far as i know, i cannot specify int32, string, or anything else with "As Object = {...,...,...,..}"

i never noticed that exicute button in the test tool before.

 

 

Action: AddPortMapping
{
    Argument: [in] NewRemoteHost => RemoteHost
    Argument: [in] NewExternalPort => ExternalPort
    Argument: [in] NewProtocol => PortMappingProtocol
    Argument: [in] NewInternalPort => InternalPort
    Argument: [in] NewInternalClient => InternalClient
    Argument: [in] NewEnabled => PortMappingEnabled
    Argument: [in] NewPortMappingDescription => PortMappingDescription
    Argument: [in] NewLeaseDuration => PortMappingLeaseDuration
}

In NewRemoteHost => State Variable: (    ) string RemoteHost  
In NewExternalPort => State Variable: (    ) ui2 ExternalPort  
In NewProtocol => State Variable: (    ) string PortMappingProtocol  (Allowed:'TCP', 'UDP')
In NewInternalPort => State Variable: (    ) ui2 InternalPort  
In NewInternalClient => State Variable: (    ) string InternalClient  
In NewEnabled => State Variable: (    ) boolean PortMappingEnabled  
In NewPortMappingDescription => State Variable: (    ) string PortMappingDescription  
In NewLeaseDuration => State Variable: (    ) ui4 PortMappingLeaseDuration  

NewRemoteHost: Unicode String: (blank)

 

NewExternalPort: Unsigned 2byte Integer: 45000

NewProtocol: Unicode String: UDP

NewInternalPort: Unsigned 2byte integer: 45000

NewInternalClient: Unicode String: 192.168.1.13 (yes, doubled checked IP with IPConfig)

NewEnabled: Boolean Type: True

NewPortMappingDiscription: UnicodeString: Test

NewLeaseDuration:Unsigned 4-byte Integer: 0

result: UPNP_E_Invalid_Arguments , HResult: 0x80040208

Port 45000 is not mapped (i have a UPnP port checking tool) and have tried other ports.

 

i'll take a look through the link you provided above.

Also, i'd like to refer to: http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

if it's a Type-Variable-Mismatch (forexample, 45000 being read as &45000 Hex = 282,624 or as byte = etc....) then the answer may be in there under "Using Objects" section.

 

 

 

Coordinator
Jan 26, 2012 at 4:59 AM
Edited Jan 28, 2012 at 12:39 AM



Hey isnt this the same error you were getting with the other UPnP framework here (assuming this is you):
 
 
Are you sure its not your router mate?
Coordinator
Jan 26, 2012 at 4:59 AM
Edited Jan 28, 2012 at 12:38 AM

Also, just try different things, eg. dont specify external port, try null for remote host, do this in the ManagedUPnP Test app.

Jan 26, 2012 at 2:44 PM
Edited Jan 26, 2012 at 2:54 PM

 

FOUND IT!!!!!


i noticed that "WANIPConnection:1" had a "TotalNumberOfConnections" at EXACTLY 32... hum... odd that it's an exact Word, right? (as in bit,byte,word)

 

so i used the tool to delete all the Torrent ports that were open. (somewhere, someplace, i read about some routers being picky about low maximum port numbers - i think it was a link you gave me a while back about port hacking)

i took it down to 26 UPNP entries.

I tried again to open a port using the tool and VOILA! EURIKA!

the error wasn't the values or the transfer of the variables. It appears the error is that the router maxes out with 32 entries.

I also notice that when telling it to open a UDP port it opened both UDP and TCP, so 28 ports are now in use.
(Router design? common UDP effect? Glitch? doesn't matter. no biggie.)

So here's my next question:

How do i find out what the maximum number of ports are for a routing device?

how do i know what ports to close to make room for the new ports?

How do my other programs do UPnP if they can't add to the routing table because it was maxed at 32 ports?
(i'm guessing some of these can be answered with these new (link:Teredo) tunneling that i found. hum...)

Coordinator
Jan 27, 2012 at 10:25 AM
Edited Jan 27, 2012 at 10:29 AM

vburgess,

Im glad you found the problem, i thought it had to be something to do with your particular hardware, as for finding out what the limit is, i dont think you can, there is certainly nothing I have found in the standard UPnP Gateway device documents describing an action or state variable to get the maximum number of port mappings allowed. Also, the opening of both protocols irrespective of what you specify is definitely a Firmware glitch / bug, have you considered updating the firmware?

Tunneling could help, but it is reliant on the fact that you have an IPV6 source point and endpoint to use for the tunnel, come to think of it, any type of tunnelling could solve this problem but you would still need to setup the ports for the tunnel.

You can find out what port mappings are currently set by using the GetGenericPortMappingEntry action and specifying an index of the mapping you want, which should be 0 to GetPortMappingNumberOfEntries-1, therefore, you could use the action to get the oldest port mappings (hopefully this would usually be the ones at index 0 and below) and then delete those port mappings using DeletePortMapping. ie.

Dim loIn() As Object = { }
Dim loOut() As Object
loOut = lsService.InvokeAction("GetPortMappingNumberOfEntries", loIn)
Dim liNumberOfEntries = loOut(0)

...


' GEt mapping information
Dim loIn() As Object = { 0 } ' Index of mapping to get
loOut = lsService.InvokeAction("GetGenericPortMappingEntry", loIn)

' Delete the mapping
Dim loDeleteIn() As Object = { loOut(0), loOut(1), loOut(2) } ' RemoteHost, ExternalPort, Protocol
lsService.InvokeAction("DeletePortMapping", loDeleteIn) 

All the information you need can be found in that PDF document:

http://www.upnp.org/specs/gw/UPnP-gw-WANPPPConnection-v1-Service.pdf

However, this stuff would be much easier if you use the generated WANPPPConnection1 class that you generated with your device, this way you can just call:

Dim lsService = new WANPPPConnection1(lsDiscoveredService)
Dim liNumberOfEntries = lsService.GetPortMappingNumberOfEntries()
Dim lsRemoteHost As String, liExternalPort As Integer, lsExternalProtocol As String
Dim liInternalPort As Integer, lsInternalClient As String, lbEnabled AS Boolean, lsDesc As String, liLeaseDuration as Integer

' You could do a for loop here and delete as many ports as are needed for your app range of 0 to liNumberOfEntries-1
Dim liIndexToDelete As Integer = 0
lsService.GetSpecificPortMappingEntry(
	liIndexToDelete, lsRemoteHost, liExternalPort, lsExternalProtocol, liInternalPort, 
	lsInternalClient, lbEnabled, lsDesc, liLeaseDuration)

lsService.DeletePortMapping(lsRemoteHost, liExternalPort, lsExternalProtocol)

Just means you dont have to deal with all the arrays and stuff, saying that though, I think this limit on routers is rare, dont quote me on it, but my router is just a cheap old netgear and yet I have never reached the limit and I have had more than 32 mappings at once, are you sure this isnt an isolated case with your hardware?

NOTE: I didnt test any of this code here, and its VB so I probably some syntax errors somewhere along the way. Let me know how you go.

Jan 27, 2012 at 1:19 PM

VB Arrays are a piece of cake for me, and I'm beginning to get a grip on  your library's functions. The examples you give are extremely helpful when it comes to the variables required for your function calls.

I'll give it some tests when I'm off from work on Monday and not doing my 12 hour shifts but I'm not expecting any major problems.

AGAIN, Thanks for the help. You are a Network coding GURU.