cancel
Showing results for 
Search instead for 
Did you mean: 

How to provide userid and pwd to a web service from a .NET client?

Former Member
0 Kudos

I am trying to call a webservice on the ESOA located at sdn.sap.com and am getting an authorization error.

(Note: I am sure teh USERID and PASSWORD is valid).

Here is my Code

//Instantiate the web service

sap.CustomerERPSimpleByIDQueryResponse_InService sapService = new sap.CustomerERPSimpleByIDQueryResponse_InService();

//Define Login ICredentials cred = new NetworkCredential ("USERID", "PASSWORD");

sapService.Credentials = cred;

//Instantiate the parameters pass the the method

sap.CustERPSimplByIDQry_sSel selection = new sap.CustERPSimplByIDQry_sSel();

sap.CustERPSimplByIDQry_sProcgCond proccondin = new sap.CustERPSimplByIDQry_sProcgCond();

sap.CustERPSimplByIDRsp_sProcgCond proccondout = new sap.CustERPSimplByIDRsp_sProcgCond();

sap.NOSC_Log log = new sap.NOSC_Log();

//Select Customer with ID = "1"

selection.ID = "1";

//Call the web method

sapService.CustomerERPSimpleByIDQueryResponse_In(selection, proccondin, out proccondout, out log);

However when I tryo to call the web method, I get this exception:

System.Net.WebException was unhandled

Message="The request failed with HTTP status 401: Unauthorized."

Source="System.Web.Services"

StackTrace:

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

at WindowsFormsApplication1.sap.CustomerERPSimpleByIDQueryResponse_InService.CustomerERPSimpleByIDQueryResponse_In(CustERPSimplByIDQry_sSel CustomerERPSimpleSelectionByID, CustERPSimplByIDQry_sProcgCond ProcessingConditions, CustERPSimplByIDRsp_sProcgCond& ProcessingConditions1, NOSC_Log& Log)

at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e)

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)

at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.Run(Form mainForm)

at WindowsFormsApplication1.Program.Main()

at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

InnerException:

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

for SAP service:

NetworkCredentials cred = new NetworkCredentials("SAPUSER", "SAPPASSWORD");

service.credentials = cred;

for IIS service:

service.Credentials = CredentialCache.DefaultCredentials;

regards

Answers (0)