2012-03-30 77 views
0

试图按照此MSDN教程来获取Web响应,但没有得到任何回应,所以想知道如果我可以使用除默认或网络凭证之外的其他任何内容来发送Web请求。System.Net.WebRequest自定义证书

我使用它在SharePoint自定义计时器作业安装在使用功能接收器,这里的代码,

计时器作业类execute方法

using System; 
using System.Collections.Generic; 
using System.Text; 
using Microsoft.SharePoint; 
using Microsoft.SharePoint.Administration; 
using System.Diagnostics; 

namespace EmailJob.FeatureCode 
{ 
    class SharePointWarmupJob : SPJobDefinition 
    { 
     private const string JOB_NAME = "Email Job"; 

     public SharePointWarmupJob() : base() { } 

     public SharePointWarmupJob(SPWebApplication webApp) 
      : base(JOB_NAME, webApp, null, SPJobLockType.ContentDatabase) 
     { 
      this.Title = JOB_NAME; 
     } 

     public override void Execute(Guid targetInstanceId) 
     { 
      Debug.Assert(false); 

      if (this.WebApplication.Sites.Count > 0) 
       WarmUpSharePointSite(this.WebApplication.Sites[0]); 
     } 

     private void WarmUpSharePointSite(SPSite siteCollection) 
     { 
      System.Net.WebRequest request = System.Net.WebRequest.Create(siteCollection.Url); 
      request.Credentials = System.Net.CredentialCache.DefaultCredentials; 
      request.Method = "GET"; 

      System.Net.WebResponse response = request.GetResponse(); 
      response.Close(); 
     } 
    } 
} 

功能接收器类

using System; 
using System.Collections.Generic; 
using System.Text; 
using Microsoft.SharePoint; 
using Microsoft.SharePoint.Administration; 
using EmailJob.FeatureCode; 

namespace EmailJob 
{ 
    class EmailJobFeature : SPFeatureReceiver 
    { 
     private const string JOB_NAME = "Email Job"; 

     public override void FeatureInstalled(SPFeatureReceiverProperties properties) 
     { 
      throw new NotImplementedException(); 
     } 

     public override void FeatureUninstalling(SPFeatureReceiverProperties properties) 
     { 
      throw new NotImplementedException(); 
     } 

     public override void FeatureActivated(SPFeatureReceiverProperties properties) 
     { 
      SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; 
      if (webApp == null) 
       throw new NotImplementedException("Error obtaining reference to Web application"); 

      foreach (SPJobDefinition job in webApp.JobDefinitions) 
       if (job.Name == JOB_NAME) job.Delete(); 

      SharePointWarmupJob warmupJob = new SharePointWarmupJob(webApp); 

      SPMinuteSchedule schedule = new SPMinuteSchedule(); 
      schedule.BeginSecond = 0; 
      schedule.EndSecond = 59; 
      schedule.Interval = 5; 

      warmupJob.Schedule = schedule; 

      warmupJob.Update(); 
     } 

     public override void FeatureDeactivating(SPFeatureReceiverProperties properties) 
     { 
      SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; 
      if (webApp == null) 
       throw new NotImplementedException("Error obtaining reference to Web application"); 

      foreach (SPJobDefinition job in webApp.JobDefinitions) 
       if (job.Name == JOB_NAME) job.Delete(); 

      throw new NotImplementedException(); 
     } 
    } 
} 

当我尝试调试时,它在代码行没有回应

"System.Net.WebResponse response = request.GetResponse();" 

这是我的VPC,并以管理员身份登录,我甚至注释了凭据代码行或尝试过网络凭据,但它似乎不起作用。

哦,是的,当我尝试测试在控制台应用程序代码,它说的凭据属性,除了加密空=真

干杯!

回答