Index: Utilities.tcl
==================================================================
--- Utilities.tcl
+++ Utilities.tcl
@@ -3390,11 +3390,11 @@
                             set partType $tns:$partType
                         }
                         ##
                         ## Convert the reference to the local tns space
                         ##
-                        set partType  [getQualifiedType $results $partType $tns]
+                        set partType [getQualifiedType $results $partType $tns $middleNode]
                         set refTypeInfo [GetServiceTypeDef $mode $serviceName $partType]
                         set refTypeInfo [dict get $refTypeInfo definition]
                         set tmpList [dict keys $refTypeInfo]
                         if {[llength $tmpList] == 1} {
                             ##
@@ -3404,11 +3404,11 @@
                                 ##
                                 ## To at type, so redefine the name
                                 ##
                                 set partName [lindex [dict keys $refTypeInfo] 0]
                             }
-                            set partType [getQualifiedType $results [dict get $refTypeInfo $partName type] $tns]
+                            set partType [getQualifiedType $results [dict get $refTypeInfo $partName type] $tns $middleNode]
                         }
                         lappend partList $partName [list type $partType]
                     }]} {
                         lappend unknownRef($partType) $typeName
                         return \
@@ -3416,11 +3416,12 @@
                             -errorcode [list WS $mode UNKREF [list $typeName $partType]] \
                             "Unknown forward type reference {$partType} in {$typeName}"
                     }
                 } else {
                     set partName [$middleNode getAttribute name]
-                    set partType [string trimright [getQualifiedType $results [$middleNode getAttribute type string:string] $tns] {?}]
+                    set partType [string trimright \
+                        [getQualifiedType $results [$middleNode getAttribute type string:string] $tns $middleNode] {?}]
                     set partMax [$middleNode getAttribute maxOccurs 1]
                     if {$partMax <= 1} {
                         lappend partList $partName [list type $partType comment $comment]
                     } else {
                         lappend partList $partName [list type [string trimright ${partType} {()}]() comment $comment]
@@ -3643,21 +3644,21 @@
             ##
         }
         element {
             catch {
                 set partName [$node getAttribute name]
-                set partType [string trimright [getQualifiedType $results [$node getAttribute type string] $tns] {?}]
+                set partType [string trimright [getQualifiedType $results [$node getAttribute type string] $tns $node] {?}]
                 set partMax [$node getAttribute maxOccurs 1]
                 if {$partMax <= 1} {
                     set partList [list $partName [list type $partType comment {}]]
                 } else {
                     set partList [list $partName [list type [string trimright ${partType} {()}]() comment {}]]
                 }
             }
         }
         extension {
-            set baseName [getQualifiedType $results [$node getAttribute base string] $tns]
+            set baseName [getQualifiedType $results [$node getAttribute base string] $tns $node]
             set baseTypeInfo [TypeInfo Client $serviceName $baseName]
             ::log::logsubst debug {\t base name of extension is {$baseName} with typeinfo {$baseTypeInfo}}
             if {[lindex $baseTypeInfo 0]} {
                 if {[catch {::WS::Utils::GetServiceTypeDef Client $serviceName $baseName}]} {
                     set baseQuery [format {child::*[attribute::name='%s']} $baseName]
@@ -3751,14 +3752,14 @@
                                 if {[info exists simpleTypes($mode,$serviceName,$tns:$partName)]} {
                                   set additional_defininition_elements $simpleTypes($mode,$serviceName,$tns:$partName)
                                   set partType [dict get $additional_defininition_elements baseType]
                                 }
                             } else {
-                                set partType [getQualifiedType $results [$element getAttribute type string] $tns]
+                                set partType [getQualifiedType $results [$element getAttribute type string] $tns $element]
                             }
                         } else {
-                            set partType [getQualifiedType $results [$element getAttribute type string] $tns]
+                            set partType [getQualifiedType $results [$element getAttribute type string] $tns $element]
                         }
                     }
                     if {[string length $occurs]} {
                         set partMax [$element getAttribute maxOccurs 1]
                         if {$partMax < $occurs} {
@@ -3900,11 +3901,11 @@
         ::log::logsubst debug {\t Type $tns:$typeName is already defined -- leaving}
         return
     }
     set typeType ""
     if {[$node hasAttribute type]} {
-        set typeType [getQualifiedType $results [$node getAttribute type string] $tns]
+        set typeType [getQualifiedType $results [$node getAttribute type string] $tns $node]
     }
     ::log::logsubst debug {Elemental Type is $typeName}
     set partList {}
     set partType {}
     set isAbstractType false
@@ -3976,16 +3977,16 @@
             if {[llength $childList]} {
                 ##
                 ## Element defines another element layer
                 ##
                 set partName [$element getAttribute name]
-                set partType [getQualifiedType $results $partName $tns]
+                set partType [getQualifiedType $results $partName $tns $element]
                 parseElementalType $mode results $serviceName $element $tns
             } else {
                 set partName [$element getAttribute name]
                 if {[$element hasAttribute type]} {
-                    set partType [getQualifiedType $results [$element getAttribute type] $tns]
+                    set partType [getQualifiedType $results [$element getAttribute type] $tns $element]
                 } else {
                     set partType xs:string
                 }
 
             }
@@ -4032,13 +4033,13 @@
                 }
             }
         }
         # have an element with a type only, so do the work here
         if {[$node hasAttribute type]} {
-            set partType [getQualifiedType $results [$node getAttribute type] $tns]
+            set partType [getQualifiedType $results [$node getAttribute type] $tns $node]
         } elseif {[$node hasAttribute base]}  {
-            set partType [getQualifiedType $results [$node getAttribute base] $tns]
+            set partType [getQualifiedType $results [$node getAttribute base] $tns $node]
         } else {
             set partType xs:string
         }
         set partMax [$node getAttribute maxOccurs 1]
         if {$partMax <= 1} {
@@ -4533,10 +4534,11 @@
 #
 # Arguments :
 #       serviceInfo - service information dictionary
 #       type        - type to get local qualified type on
 #       tns         - current namespace
+#       node        - optional XML item to search for xmlns:* attribute
 #
 # Returns :     nothing
 #
 # Side-Effects :        None
 #
@@ -4555,17 +4557,28 @@
 # Version     Date     Programmer   Comments / Changes / Reasons
 # -------  ----------  ----------   -------------------------------------------
 #       1  02/24/2011  G. Lester    Initial version
 #
 ###########################################################################
-proc ::WS::Utils::getQualifiedType {serviceInfo type tns} {
+proc ::WS::Utils::getQualifiedType {serviceInfo type tns {node {}}} {
 
     set typePartsList [split $type {:}]
     if {[llength $typePartsList] == 1} {
         set result $tns:$type
     } else {
         lassign $typePartsList tmpTns tmpType
+        if {$node ne {}} {
+            set attr xmlns:$tmpTns
+            if {[$node hasAttribute $attr]} {
+                set xmlns [$node getAttribute $attr]
+                if {[dict exists $serviceInfo tnsList url $xmlns]} {
+                    set result [dict get $serviceInfo tnsList url $xmlns]:$tmpType
+                    return $result
+                }
+                # fail later if namespace not found
+            }
+        }
         if {[dict exists $serviceInfo tnsList tns $tmpTns]} {
             set result [dict get $serviceInfo tnsList tns $tmpTns]:$tmpType
         } elseif {[dict exists $serviceInfo types $type]} {
             set result $type
         } else {
@@ -4572,12 +4585,12 @@
             ::log::log error $serviceInfo
             ::log::logsubst error {Could not find tns '$tmpTns' in '[dict get $serviceInfo tnsList tns]' for type {$type}}
             set result $tns:$type
             return -code error
         }
+    }
 
-    }
     return $result
 }
 
 ###########################################################################
 #

