我的wsdl文件的URL在浏览器中通过提供用户名和密码打开。如何以实用的方式为该wsdl提供用户名和密码以获取xml格式的wsdl。以下是代码供参考。
class Program {
static void Main(string[] args)
{
WebServiceInfo webServiceInfo = WebServiceInfo.OpenWsdl("https://xyz.com/partners?wsdl");
Console.WriteLine(string.Format("WebService: {0}", webServiceInfo.Url));
}
public class WebServiceInfo
{
WebMethodInfoCollection _webMethods = new WebMethodInfoCollection();
Uri _url;
static Dictionary<string, WebServiceInfo> _webServiceInfos =
new Dictionary<string, WebServiceInfo>();
private WebServiceInfo(Uri url)
{
if (url == null)
throw new ArgumentNullException("url");
_url = url;
_webMethods = GetWebServiceDescription(url);
}
public static WebServiceInfo OpenWsdl(string url)
{
Uri uri = new Uri(url);
return OpenWsdl(uri);
}
}
谢谢
答案 0 :(得分:0)
[假设是我们正在谈论的Windows身份验证...]
System.Net.Credentials为此提供了便利,现在无法对其进行测试,但这应该接近您需要做的事情:
//request object provided for reference purposes
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://url");
//add the following
request.Credentials = new System.Net.NetworkCredential(userName, password, domain);