Internal Server Error 500  executing ArcPy GPK

Discussion created by jptasznik on Nov 5, 2013
Latest reply on Nov 11, 2013 by jptasznik
I have created an ArcPy GP Function based on a model I built.
I can execute it in Desktop and it behaves as expected.
I publish the package and when I run my program against it I get the following exception:

System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request
   at System.Net.WebClient.DownloadString(Uri address)
   at ESRI.ArcGIS.Client.Tasks.TaskBase.Request(String url, Dictionary`2 parameters, Boolean forcePost)
   at ESRI.ArcGIS.Client.Tasks.Geoprocessor.Execute(List`1 parameters)
   at RoutingWithGeoProcesingPackage.Program.RunTool(Geoprocessor gpTask) in c:\Code\CAD\Prototypes\GIS\RoutingWithGeoProcesingPackage\RoutingWithGeoProcesingPackage\Program.cs:line 112
   at RoutingWithGeoProcesingPackage.Program.Main() in c:\Code\CAD\Prototypes\GIS\RoutingWithGeoProcesingPackage\RoutingWithGeoProcesingPackage\Program.cs:line 48

Here is the code:
# Import arcpy module
import arcpy

# Check out any necessary licenses

# Script arguments
Stops = arcpy.GetParameterAsText(0)

Barriers = arcpy.GetParameterAsText(1)

Impedance_Attribute = arcpy.GetParameterAsText(3)
if Impedance_Attribute == '#' or not Impedance_Attribute:
    Impedance_Attribute = "Time" # provide a default value if unspecified

Restrictions = arcpy.GetParameterAsText(4)
if Restrictions == '#' or not Restrictions:
    Restrictions = "Oneway" # provide a default value if unspecified

Vehicle_Weight = arcpy.GetParameterAsText(5)

Vehicle_Height = arcpy.GetParameterAsText(6)

Directions_XML_File = arcpy.GetParameterAsText(7)

# Local variables:
Input_Network_Dataset = "C:\\ServerData\\GCSRouting.gdb\\NetworkDataset_Data\\Streets_ND"
Route = "SolvedRoute"

# Process: Make Route Layer
arcpy.MakeRouteLayer_na(Input_Network_Dataset, Route, Impedance_Attribute, "USE_INPUT_ORDER", "PRESERVE_BOTH", "NO_TIMEWINDOWS", "", "ALLOW_UTURNS", Restrictions, "NO_HIERARCHY", "", "TRUE_LINES_WITH_MEASURES", "")

# Process: Add Vehicle Weight
if Vehicle_Weight:
 arcpy.UpdateAnalysisLayerAttributeParameter_na(Route, "WeightRestrtiction", "Vehicle Weight", Vehicle_Weight)

# Process: Add Vehicle Height
if Vehicle_Height:
 arcpy.UpdateAnalysisLayerAttributeParameter_na(Route, "HeightRestriction", "Vehicle Height", Vehicle_Height)

# Process: Add Stops
arcpy.AddLocations_na(Route, "Stops", Stops, "", "5000 Meters", "", "Driveways SHAPE;Streets SHAPE;Driveway_Endpoints SHAPE;Streets_ND_Junctions NONE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "Driveways #;Streets #;Driveway_Endpoints #;Streets_ND_Junctions #")

# Process: Add Barriers
if Barriers:
 arcpy.AddLocations_na(Route, "Point Barriers", Barriers,"", "5000 Meters", "", "Driveways SHAPE;Streets SHAPE;Driveway_Endpoints SHAPE;Streets_ND_Junctions NONE", "MATCH_TO_CLOSEST", "CLEAR", "NO_SNAP", "5 Meters", "INCLUDE", "Driveways #;Streets #;Driveway_Endpoints #;Streets_ND_Junctions #")

# Process: Directions
arcpy.env.workspace = "in_memory"
if Directions_XML_File == '#' or not Directions_XML_File:
    Directions_XML_File = arcpy.CreateUniqueName("Directions.xml", arcpy.env.scratchFolder)

arcpy.AddMessage("Directions XML = " + Directions_XML_File)
arcpy.Directions_na(Route, "XML", Directions_XML_File, "Miles", "REPORT_TIME", "Time", "en", "NA Desktop")
#, "")

# Process: Select Data
SelectResults = arcpy.SelectData_management(Route, "Routes")
SelectLayer = SelectResults.getOutput(0)

OutFeatureSet = arcpy.FeatureSet()
arcpy.SetParameter(2, OutFeatureSet)
arcpy.SetParameter(7, Directions_XML_File)

Any ideas?