SharePoint WebServices WebアプリケーションがNTLM認証を使用している場合は、これを試すことができます
ug.ClientCredentials.Windows.ClientCredential = new NetworkCredential("myusername", "mypassword");
そしてあなたの中でapp.config
<security mode="Transport">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
編集:
WebアプリケーションではWebサービスにアクセスするためにNTLM認証が無効になっているため、最初にAuthentication.asmx Webサービスでログインし、認証Cookieを取得して、次のような他のWebサービス呼び出しで送信する必要があります。
string cookie = "";
LoginResult loginResult;
string result;
AuthenticationSoapClient authentication = new AuthenticationSoapClient();
UserGroupSoapClient ug = new UserGroupSoapClient();
using(OperationContextScope scope = new OperationContextScope(authentication.InnerChannel))
{
loginResult = authentication.Login("user", "pass");
if (loginResult.ErrorCode == LoginErrorCode.NoError)
{
MessageProperties props = OperationContext.Current.IncomingMessageProperties;
HttpResponseMessageProperty prop = props[HttpResponseMessageProperty.Name] as HttpResponseMessageProperty;
string cookies = prop.Headers["Set-Cookie"];
// You must search cookies to find cookie named loginResult.CookieName and set its value to cookie variable;
cookie = cookies.Split(';').SingleOrDefault(c => c.StartsWith(loginResult.CookieName));
}
}
HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers.Add(System.Net.HttpRequestHeader.Cookie, cookie);
using (new OperationContextScope(ug.InnerChannel))
{
OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequestProperty);
result = ug.GetGroupCollectionFromUser(LoginName).ToString();
}
app.configで、すべてのバインディングのallowCookiesプロパティがfalseであることを確認してください。
<basicHttpBinding>
<binding name="AuthenticationSoap" allowCookies="false"/>
<binding name="UserGroupSoap" allowCookies="false"/>
</basicHttpBinding>