XML : How do I add windows authentification to my web service

I have WCF Service, my goal is to be able to retrieve information from my server using GET and POST. I almost got it to work. My problem is that to be able to access the information on the server I need to enter my credentials, otherwise I get the error 401 unauthorized

I tried a few different things but I'm still new at using XML and when I try to add some code I always get errors.

This is my code:

C#

  [ServiceContract]      public interface IRestServiceImpl      {          [OperationContract]          [WebInvoke(Method = "GET",              ResponseFormat = WebMessageFormat.Xml,              BodyStyle = WebMessageBodyStyle.Wrapped,              UriTemplate = "xml/{id}")]          string XMLData(string id);            [OperationContract]          [WebInvoke(Method = "GET",              ResponseFormat = WebMessageFormat.Json,              BodyStyle = WebMessageBodyStyle.Wrapped,              UriTemplate = "json/{id}")]          string JSONData(string id);      }    

XML

  <?xml version="1.0"?>  <configuration>      <system.web>      <compilation debug="true" targetFramework="4.0" />    </system.web>    <system.serviceModel>      <services>        <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">          <!-- Service Endpoints -->          <!-- Unless fully qualified, address is relative to base address supplied above -->          <endpoint address ="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">            <!--                 Upon deployment, the following identity element should be removed or replaced to reflect the                 identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity                 automatically.            -->          </endpoint>        </service>      </services>        <behaviors>        <serviceBehaviors>          <behavior name="ServiceBehaviour">            <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->            <serviceMetadata httpGetEnabled="true"/>            <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->            <serviceDebug includeExceptionDetailInFaults="false"/>          </behavior>        </serviceBehaviors>        <endpointBehaviors>          <behavior name="web">            <webHttp/>          </behavior>        </endpointBehaviors>      </behaviors>      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />    </system.serviceModel>    <system.webServer>      <modules runAllManagedModulesForAllRequests="true"/>    </system.webServer>    </configuration>    

Feel free to leave any comments or ask any questions

No comments:

Post a Comment