使用预防性身份验证消费Web服务 [英] Consumption of webservice with preventive authentication

查看:95
本文介绍了使用预防性身份验证消费Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello, sorry for my translation, I hope you understand, at the moment I am making the consumption of a webservice from an application developed in c #. The consumption from the SoapUI program is achieved successfully, activating a preference that is called, preventive authentication, its user and password are configured in the tab called "Auth".
However, when I try to send a header with the user and the password returns the error "(500) Internal error of the server", the webservice associates it with the project as a web reference, as recommended by one of the pages in which I found a solution .





我尝试了什么:



*到目前为止,我将WS作为服务引用和Web引用关联到项目中。

*我添加了以下代码行以便发送头文件,因此重新创建预防性身份验证。



What I have tried:

*So far, I associated the WS to the project as a service reference and as a web reference.
*I added the following lines of code to send in the header the credentials and thus recreate the preventive authentication.

string auth = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(wsParams[0] + ":" + wsParams[1]));
                req.PreAuthenticate = true;
                req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
                req.Headers.Add("Authorization", auth);
                WebResponse resp = req.GetResponse();





*获得答案(500)后,我尝试重新创建SoapUI标题中的用户和密码,没有成功。这让我进入第二次代码测试。

*尝试使用前面代码中的credentials属性发送身份验证,但以同样的方式我得到答案(500)





*After obtaining the answer (500), I tried to recreate by SoapUI the user and password in the header, without success. Which brings me to the second code test.
*Try to send the authentication using the credentials property from the previous code, but in the same way I get the answer (500)

NetworkCredential networkCredential = new NetworkCredential(wsParams[0], wsParams[1]);
				req.Credentials = networkCredential;
                req.PreAuthenticate = true;
				WebResponse myWebResponse = req.GetResponse();





从这里开始,我已经尝试了几乎所有东西,但仍然无法获得通过代码消耗ws,我非常感谢我如何消费。

注意



From here on I have tried almost everything but still can not get the consumption of the ws by code, I would greatly appreciate an idea of ​​how I can make the consumption.
Be attentive

推荐答案

// Create the network credentials and assign
// them to the service credentials
NetworkCredential netCredential = new NetworkCredential("wsParams[0]", "wsParams[1]");
Uri uri = new Uri(service.Url);
ICredentials credentials = netCredential.GetCredential(uri, "Basic");
service.Credentials = credentials;

//  set PreAuthenticate to true
// authentication will not be sent.
service.PreAuthenticate = true;





------------

使用req.credentials会出现WebMethods问题,因为标题部分不包含甚至Preauthentication设置为true所以它返回



------------
Using req.credentials gives problem with WebMethods because the header part doesnt contain even Preauthentication is set to true So it returns

500 Internal Server Error




request.Credentials = new NetworkCredential(username,password)."







使用基本身份验证调用Web服务 - IntelliTect [ ^ ]


这篇关于使用预防性身份验证消费Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆