2010-03-21 103 views
0

我正在爲Windows 7 Phone Series平臺製作​​我的第二個應用程序,並且我似乎無法使用https連接到SharePoint服務器。Windows Phone 7通過SOAP連接到SharePoint

99%以下不是我的代碼。我從http://blog.daisley-harrison.com/blog/post/Practical-Silverlight-and-SharePoint-Integration-Part-Two.aspx中借了下來,直到我可以進一步理解SOAP在W7P系列中的工作原理。

我知道我需要一些發送憑據的方式,但贏得7 API似乎並沒有讓你。 ServiceReferences.ClientConfig

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <basicHttpBinding> 
       <binding name="ViewsSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Buffered"> 
        <security mode="TransportCredentialOnly"/> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="https://my.secureconnection.com/_vti_bin/views.asmx" 
       binding="basicHttpBinding" bindingConfiguration="ViewsSoap" 
       contract="SharePointListService.ViewsSoap" name="ViewsSoap" /> 
     </client> 
    </system.serviceModel> 
</configuration> 

這是我的maincode頁:

public partial class MainPage : PhoneApplicationPage 
    { 
     public MainPage() 
     { 
      InitializeComponent(); 

      SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape; 
      try 
      { 
       Uri serviceUri = new Uri("https://my.secureconnection.com" + SERVICE_LISTS_URL); 
       BasicHttpBinding binding; 
       if (serviceUri.Scheme == "https") 
       { 
        binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); 
       } 
       else 
       { 
        binding = new BasicHttpBinding(BasicHttpSecurityMode.None); 
       } 
       EndpointAddress endpoint = new EndpointAddress(serviceUri); 
       ListsSoapClient listSoapClient = new ListsSoapClient(binding, endpoint); 


       NetworkCredential creds = new NetworkCredential("administrator", "iSynergy1", "server001"); 
       //listSoapClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Identification; 
       //listSoapClient.ClientCredentials.Windows.ClientCredential = creds; 

       listSoapClient.GetListCollectionCompleted += new EventHandler<GetListCollectionCompletedEventArgs>(listSoapClient_GetListCollectionCompleted); 
       listSoapClient.GetListCollectionAsync(); 
      } 
      catch (Exception exception) 
      { 
       handleException("Failed to get list collection", exception); 
      } 
     } 
     #region ShowExceptionDetail Property 
     public static readonly DependencyProperty ShowExceptionDetailDependencyProperty = DependencyProperty.Register("ShowExceptionDetail",typeof(bool),typeof(Page),new PropertyMetadata(true)); 
     public bool ShowExceptionDetail 
     { 
      get { return (bool)GetValue(ShowExceptionDetailDependencyProperty); } 
      set { SetValue(ShowExceptionDetailDependencyProperty, value); } 
     } 
     #endregion 
     private void handleException(string context, Exception exception) 
     { 
      this.Dispatcher.BeginInvoke(delegate() 
      { 
       bool showExceptionDetail = this.ShowExceptionDetail; 

       string message = ""; 

       Exception next = exception; 
       do 
       { 
        if (message.Length > 0) { message += ";" + Environment.NewLine; } 
        if (next.Message == null || next.Message.Length == 0) { message += next.GetType().FullName; } 
        else { message += next.Message; } 
        if (showExceptionDetail) 
        { 
         if (next.Data.Count > 0) 
         { 
          bool first = true; 
          message += " {"; 
          foreach (string key in next.Data.Keys) 
          { 
           if (first) { first = false; } 
           else { message += ", "; } 
           message += key + "=\"" + next.Data[key] + "\""; 
          } 
          message += "}"; 
         } 
         if (next.InnerException != next) 
         { 
          next = next.InnerException; 
          continue; 
         } 
        } 
        next = null; 
       } 
       while (next != null); 
       MessageBox.Show(message, context, MessageBoxButton.OK); 
      }); 
     } 

     private const string SERVICE_LISTS_URL = "/_vti_bin/lists.asmx"; 
     void listSoapClient_GetListCollectionCompleted(object sender, GetListCollectionCompletedEventArgs e) 
     { 
      try { myList.Text = e.Result.ToString(); } 
      catch (Exception exception) { handleException("Failed to get list collection", exception); } 
     } 
    } 

當我運行這一點,它得到了 「ListsSoapClient」 的一部分,它打破。如果您深入瞭解錯誤輸出,則表示訪問被拒絕。我嘗試過發送憑證的各種方法,但似乎沒有任何工作。 「ClientCredentials.Windows」不受支持,並且ClientCredentials.UsersName.Username是隻讀的。

+0

在在MSDN論壇上我獲得了一些回覆有遇到類似問題的人。它看起來像是當前SDK中的一個錯誤。 http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/43a84dff-9447-4e95-8040-8a5447514fa0 – 2010-03-21 23:02:36

回答