代码之家  ›  专栏  ›  技术社区  ›  Mitchell Skurnik

Windows Phone 7通过SOAP连接到SharePoint

  •  0
  • Mitchell Skurnik  · 技术社区  · 16 年前

    我正在为Windows7电话系列平台制作第二个应用程序,似乎无法使用HTTPS连接到SharePoint服务器。

    以下99%不是我的代码。我从那里借的 http://blog.daisley-harrison.com/blog/post/Practical-Silverlight-and-SharePoint-Integration-Part-Two.aspx 直到我能进一步理解在W7P系列中SOAP是如何工作的。

    我知道我需要某种方式来发送凭证,但是Win7API似乎不允许您这样做。 服务引用.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>
    

    这是我的主代码页:

        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); }
            }
        }
    

    当我运行这个,它到达“listsoacplient”部分时,它会断开。如果深入研究错误输出,它会说访问被拒绝。我尝试过各种发送凭据的方法,但似乎都不管用。”不支持clientcredentials.windows,clientcredentials.usersname.username为只读。

    推荐文章