本文介绍了在控制台应用程序中调用https Webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在https:\\ test.com中托管了WCF网络服务:8080
现在我想在控制台应用中测试这个Web服务。
我收到以下错误
System.Web.Services.dll中出现未处理的System.Net.WebException类型异常
附加信息:请求失败,HTTP状态为401:未经授权。
我的代码是:
Hi,
I hosted the WCF webservice in https:\\test.com:8080
Now i Want to test this Webservice in Console Appliction.
I got the Following Error
An unhandled exception of type 'System.Net.WebException' occurred in System.Web.Services.dll
Additional information: The request failed with HTTP status 401: Unauthorized.
My code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using test1.ServiceReference1;
using test1.salesforce;
using System.Security.Cryptography.X509Certificates;
using System.ServiceProcess;
using System.Net;
namespace test1
{
class Program
{
static void Main(string[] args)
{
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
}
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy() {
salesforce.Service1 sv = new salesforce.Service1();
sv.GetAllData();
}
public bool CheckValidationResult(ServicePoint sp, X509Certificate cert, WebRequest req, int problem)
{
return true;
}
}
}
}
这里Salesforce是我的Web参考。
Here Salesforce is my Web Reference.
推荐答案
这篇关于在控制台应用程序中调用https Webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!