Passing Extra Parameter to asmx webservice

544 views Asked by At

I have an already existing webservice having 100s of functions being called from the application.

I need to add one more parameter (UserId) from application to webservice on each call.

I'll have to manually edit signatures of all the functions and calls from application to achieve it.

Is there a better / alternative way of sending my User Id to webservice on each call?

2

There are 2 answers

0
Shankar On

100s of method have different method signatures. If method signature shares a same object, you can add extra parameter to that object and don't need to change parameters for those methods at least.

Otherwise, have to change SOAP Header and append "UserId" in the header of every request.

Any how I think need to do lot of work..

2
choz On

If you haven't enabled session and the web service is running on the same server.

[WebMethod(EnableSession = true)]

You can store it in session,

Session["UserID"] = User.Identity.GetUserId<int>();

And access it like this,

 HttpContext.Current.Session["UserID"];