Reputation:
I have a task to invoke & connect to an Axis webservice in a dotnet web app.
The webservice, first requires authentication of username & password, which should be sent in header, only after authentication, we can call any of its method.
Now, I don't know how to pass the credentials & invoke the webservice.
I have the Java code which shows how to access the webservice, but I don't know how to do the same in .NET.
I suppose I have to use WSE 3.0.
Here is the Java code:
Service webService = new Service();
Call calling = (Call) webService.createCall();
calling.setProperty (Call.USERNAME_PROPERTY, "victor");
calling.setProperty (Call.PASSWORD_PROPERTY, "victor_s");
String userid="userid";
String password="password";
String endpoint= "SERVICEURL";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName(endpoint,methodName));
call.setProperty (Call.USERNAME_PROPERTY, "victor");
call.setProperty (Call.PASSWORD_PROPERTY, "victor_s");
String ItineraryDetailsInputXML="<?xml version=\"1.0\" encoding=\"UTF-8\"?><ItineraryDetailsInput lccp_srcstn=\"NDLS\" lccp_dstnstn=\"MAS\" lccp_trnnum=\"2616\" lccp_cls=\"SL\" lccp_resupto=\"MAS\" lccp_brdpt=\"NDLS\" lccp_day=\"27\" lccp_month=\"11\" lccp_year=\"2008\" lccp_qta=\"GN\" lccp_psgnname1=\"SANJEEV KUMAR \" lccp_psgnsex1=\"m\" lccp_psgnage1=\"60\" lccp_psgnberthpref1=\"Side_Upper\" lccp_psgnfoodpref1=\"Veg\" lccp_psgnconc1=\"SRCTZN\" lccp_psgnname2=\"Prasad\" lccp_psgnsex2=\"f\" lccp_psgnage2=\"60\" lccp_psgnberthpref2=\"Side_Lower\" lccp_psgnfoodpref2=\"\" lccp_psgnconc2=\"SRCTNW\" lccp_psgnname3=\"saa\" lccp_psgnsex3=\"m\" lccp_psgnage3=\"05\" lccp_psgnberthpref3=\"\" lccp_psgnfoodpref3=\"\" lccp_psgnconc3=\"\" lccp_psgnname4=\"ssss\" lccp_psgnsex4=\"m\" lccp_psgnage4=\"45\" lccp_psgnberthpref4=\"\" lccp_psgnfoodpref4=\"\" lccp_psgnconc4=\"\" lccp_psgnname5=\"\" lccp_psgnsex5=\"\" lccp_psgnage5=\"\" lccp_psgnberthpref5=\"\" lccp_psgnfoodpref5=\"\" lccp_psgnconc5=\"\" lccp_psgnname6=\"\" lccp_psgnsex6=\"\" lccp_psgnage6=\"\" lccp_psgnberthpref6=\"\" lccp_psgnfoodpref6=\"\" lccp_psgnconc6=\"\" userid=\""+userid+"\" password=\""+password+"\"/>";
StringBuffer buffer = new StringBuffer ();
String requestXml=ItineraryDetailsInputXML;
I don't know how to do all this passing of credentials using .NET. Hence, I request you to please guide me, on how should I tackle this. Also, if you can, please give me some sample code in .NET, where the above scenario can be done.
Upvotes: 1
Views: 2610
Reputation: 9479
Parse the WSDL in Visual Studio. Go to 'Projects' Menu along the top menu -> choose 'Add Web Reference' or 'Add service reference' depending on what version of VS you have.
Then you just make a new Client in your code. The Client will have something like 'Client Credentials' where you pass the username/pw into that:
WebServiceClient client = new WebServiceClient();
client.ClientCredentials.UserName.UserName = "xyz";
client.ClientCredentials.UserName.Password = "123";
btw it should not matter that you are connecting to an AXYS web service. The whole point of a web service is to be able to use a standard so that the client does not matter.
Upvotes: 1
Reputation: 161773
I wouldn't know either, without the WSDL, but I see no reason for you to use obsolete code like WSE. Why do you think you'd have to do that?
Also, what version of .NET are you using? What have you tried?
Is it that you don't know how to call an Axis service from .NET, or that you don't know how to call any service from .NET?
Upvotes: 1