Step 1. Accessing Web services with impersonation Credential
1. Add Service reference in Project.
2. Add Service NameSpace
using MyNameSpace.MyNameSpacee;
MyNameSpacee.MyWebServiceSoapClient myNameSpacee = new MyWebServiceSoapClient();
Step 2. change the binding in web.config/App.Config like below...
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyWebServiceSoap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration="MyWebServiceSoap"
contract="MyNameSpace.MyWebServiceSoap" name="MyWebServiceSoap" />
</client>
</system.serviceModel>
3. Add Dynamically Address for current Web
myNameSpacee.Endpoint.Address = new System.ServiceModel.EndpointAddress(SPContext.Current.Web.Url+"/_layouts/15/MyWebServices/MyWebService.asmx");
OR
Add Static Services Address in
Web.config/App.config like below inside Client Tag
<client>
<endpoint address="http://site:port/_layouts/15/MyWebServices/MyWebService.asmx""
binding="basicHttpBinding" bindingConfiguration="MyWebServiceSoap"
contract="MyNameSpace.MyWebServiceSoap" name="MyWebServiceSoap" />
</client>
myNameSpacee.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
myNameSpacee.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
4. finally Call your WebMethod
myNameSpacee.GetMYMethod();
No comments:
Post a Comment