I assume you want to use a geoprocessing service in your web app along with your map service. I give the Creating GP Services presentation at the ESRI UC, and show a demo of this. This is what I'd consider the least likely scenario in terms of GP services consuming data, thus it's not well documented. That said, you can use a geoprocessing service to work with a feature service. The feature service will stream the features over to the GP service for it to use. This requires some specific setup in both the tool and your javascript app.
First, your tool will need take a string as input. This string will represent the URL to a feature service with the query params.
For example, this would be the start code to your tool:
inFS = arcpy.GetParameterAsText(0)
featureset = arcpy.FeatureSet()
featureset.load(fs)
cnt = arcpy.GetCount_management(featureset) #Or whatever tool/workflow
The web app would pass a URL like: (note the query here is 1=1 and f=json is critical.)
http://server:6080/arcgis/rest/services/fs1/FeatureServer/0/query?where=1%3D1&returnGeometry=true&returnIdsOnly=false&returnCountOnly=false&f=json
The last part is the web app itself. With the parameter named "inputFS" inside the tool itself, this is the code used in JS:
vals = "url to fs ...JS code sets this"
gp = new Geoprocessor(gpServiceUrl);
var params = {
"inputFS" : vals
};
console.log(params);
gp.submitJob(params,gpJobComplete,gpJobStatus,gpJobFailed);
In terms of a RASTER layer...there is a tool you'd need to use the Make Image Service Layer tool, but note that this tool only works off an ImageService, not a map service with a raster. The input parameter would again be a string (the URL itself).
As you work through this, keep in mind that the map/feature service and the GP service really have nothing to do with one another. Yes you want them to consume the same underlying data. But each service by itself has no knowledge of the other. Its the web app which glues these 2 services together by passing the URL as long as the GP service is setup properly to consume it.