This is my first contribution so forgive me if it's wrong or somehow not up to par. I needed a way to secure the web services so that only an authorized application could have access to the ASMX file. After exploring several options I settled on just using Integrated Windows Authentication (which doesn't pass the username and password in clear text.) in IIS to protect the directory and having the web service client pass the credentials. This means that the username and password that protect the directory containing the ASMX file is embedded in the WebServiceClient methods. This essentially becomes "application authentication" not user authentication. For my needs user authentication will be something that happens inside my application. This of course presents us with the problem of having a username and password in the DLL, so obfuscation (or some other such method) will probably be needed to make sure that the code can't be de-compiled.
There are four new properties:
- 1. PasswordProtectWebservice - Whether or not to password protect the web service
- 2. WebserviceUsername - The username to be used to access the web service
- 3. WebservicePassword - The password to be used to access the web service
- 4. WebserviceDomain - Optionally the domain to be used to access the web service
If you choose to password protect the web service it not only embeds the code so the proxy service is passed credentials but it also turns off anonymous access on the virtual directory.
Please let me know what else I need to do. If this becomes official I'll add some documentation to the doc site to help explain it in further detail.
-Eric
PatchFileBelow:
----------------------------------------------------------------
Index: DataAccessLayer.WebServiceClient/WsEntityProviderBase.generated.cst
===================================================================
--- DataAccessLayer.WebServiceClient/WsEntityProviderBase.generated.cst (revision 711)
+++ DataAccessLayer.WebServiceClient/WsEntityProviderBase.generated.cst (working copy)
@@ -29,6 +29,11 @@
<%@ Property Name="SelectAllSuffix" Type="System.String" Default="List" Category="Style" Description="Suffix to use for all generated SELECT functions." %>
<%@ Property Name="FindSuffix" Type="System.String" Default="_Find" Category="Style" Description="Suffix to use for all generated SELECT functions." %>
+<%@ Property Name="WebserviceUsername" Type="System.String" Category="Data" Description="Webservice Username" %>
+<%@ Property Name="WebservicePassword" Type="System.String" Category="Data" Description="Web Service Password" %>
+<%@ Property Name="PasswordProtectWebservice" Type="System.Boolean" Category="Data" Description="If the web service needs top be password protected." %>
+<%@ Property Name="WebserviceDomain" Type="System.String" Category="Data" Description="Web Service Domain name" %>
+
<%@ Property Name="NameSpace" Type="System.String" Category="Style" Description="Class Namespace." %>
<%@ Property Name="DALNameSpace" Type="System.String" Category="Data" Description="DAL Namespace." %>
@@ -105,6 +110,9 @@
using System.Diagnostics;
using <%=NameSpace%>;
using <%=DALNameSpace%>.Bases;
+<% if(PasswordProtectWebservice) { %>
+using System.Net;
+<% } %>
#endregion
@@ -292,6 +300,18 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
<%=WebReferenceName%>.<%=GetClassName(primaryTable)%>[ items = proxy.<%=providerName + "_GetBy" + functionname%>(<%= GetFunctionCallParameters(junctionTableKey.ForeignKeyMemberColumns) %>, start, pagelen, out count);
@@ -330,6 +350,18 @@
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
bool result = proxy.<%=providerName%>_<%= MethodNames.Delete %>(<%= GetFunctionCallParameters(SourceTable.PrimaryKey.MemberColumns) %><% if(RowVersion != null) {Response.Write(", " + GetFieldName(RowVersion));}%>);
return result;
}
@@ -359,6 +391,18 @@
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%>[ items = proxy.<%=providerName %>_<%= MethodNames.Find %>(whereClause, start, pagelen, out count);
return Convert(items);
@@ -387,6 +431,18 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%>[ items = proxy.<%=providerName%>_<%= MethodNames.GetAll %>(start, pageLength, out count);
@@ -416,6 +472,18 @@
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%>[ items = proxy.<%=providerName%>_<%= MethodNames.GetPaged %>(whereClause, orderBy, start, pageLength, out count);
// Create a collection and fill it with the dataset
@@ -457,6 +525,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%>[ items = proxy.<%=providerName%>_GetBy<%=GetKeysName(fkeys[j].ForeignKeyMemberColumns)%>(<%= GetFunctionCallParameters(fkeys[j].ForeignKeyMemberColumns) %>, start, pageLength, out count);
return Convert(items);
@@ -513,6 +594,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%><% if (!isUnique) Response.Write("[");%> items = proxy.<%=providerName%>_GetBy<%=GetKeysName(indexes[j].MemberColumns)%>(<%= GetFunctionCallParameters(indexes[j].MemberColumns) %>, start, pageLength, out count);
return Convert(items);
@@ -540,6 +634,18 @@
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
try
{
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%> result = proxy.<%=providerName%>_<%= MethodNames.Insert %>(Convert(entity));
@@ -566,6 +672,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
try
{
proxy.<%=providerName%>_<%= MethodNames.BulkInsert %>(Convert(entityList));
@@ -598,6 +717,18 @@
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
try
{
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%> result = proxy.<%=providerName%>_<%= MethodNames.Update %>(Convert(entity));
@@ -649,6 +780,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = Url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
<% if (returnType == collectionClassName || returnType == collectionClassName.Substring (collectionClassName.LastIndexOf (".") + 1)) { %>
<%=WebReferenceName%>.<%=GetClassName(SourceTable)%>[ items = proxy.<%=providerName%>_<%=uniqueMethodName%>(start, pageLength <%=TransformStoredProcedureInputsToDataAccess(true, command.InputParameters) + TransformStoredProcedureOutputsToDataAccess(true, command.AllOutputParameters)%>);
Index: DataAccessLayer.WebServiceClient/WsNetTiersProvider.cst
===================================================================
--- DataAccessLayer.WebServiceClient/WsNetTiersProvider.cst (revision 711)
+++ DataAccessLayer.WebServiceClient/WsNetTiersProvider.cst (working copy)
@@ -17,7 +17,12 @@
<%@ Property Name="WebReferenceName" Type="System.String" Default="" Category="Decoration" Description="The WebService Proxy Class Name." %>
<%@ Property Name="ProxyClassName" Type="System.String" Default="WsProxy" Optional="True" Category="Decoration" Description="The WebService Proxy Class Name." %>
+<%@ Property Name="WebserviceUsername" Type="System.String" Category="Data" Description="Webservice Username" %>
+<%@ Property Name="WebservicePassword" Type="System.String" Category="Data" Description="Web Service Password" %>
+<%@ Property Name="PasswordProtectWebservice" Type="System.Boolean" Category="Data" Description="If the web service needs top be password protected." %>
+<%@ Property Name="WebserviceDomain" Type="System.String" Category="Data" Description="Web Service Domain name" %>
+
#region Using directives
using System;
@@ -27,6 +32,9 @@
using System.Data.Common;
using <%=BLLNameSpace%>;
using <%=DALNameSpace%>.Bases;
+<% if(PasswordProtectWebservice) { %>
+using System.Net;
+<% } %>
#endregion
@@ -225,6 +233,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = this.url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
return proxy.ExecuteNonQuery(storedProcedureName, parameterValues);
}
@@ -270,6 +291,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = this.url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
return proxy.ExecuteNonQuery((<%=WebReferenceName%>.CommandType)Enum.Parse(typeof(<%=WebReferenceName%>.CommandType), commandType.ToString(), false), commandText);
}
/// <summary>
@@ -365,6 +399,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = this.url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
return proxy.ExecuteDataSet(storedProcedureName, parameterValues);
}
@@ -412,6 +459,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = this.url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
return proxy.ExecuteDataSet((<%=WebReferenceName%>.CommandType)Enum.Parse(typeof(<%=WebReferenceName%>.CommandType), commandType.ToString(), false), commandText);
}
@@ -439,6 +499,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = this.url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
return proxy.ExecuteScalar(storedProcedureName, parameterValues);
}
@@ -485,6 +558,19 @@
{
<%=WebReferenceName%>.<%=ProxyClassName%> proxy = new <%=WebReferenceName%>.<%=ProxyClassName%>();
proxy.Url = this.url;
+
+ <% if(PasswordProtectWebservice) { %>
+
+ <% if(WebserviceDomain.Length > 0) { %>
+ //Use username, password, and domain name to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>", "<%=WebserviceDomain%>");
+ <%} else { %>
+ //Use username, and password to authenticate against the web service
+ proxy.Credentials = new NetworkCredential("<%=WebserviceUsername%>", "<%=WebservicePassword%>");
+ <% } %>
+
+ <% } %>
+
return proxy.ExecuteScalar((<%=WebReferenceName%>.CommandType)Enum.Parse(typeof(<%=WebReferenceName%>.CommandType), commandType.ToString(), false), commandText);
}
/// <summary>
Index: NetTiers.cst
===================================================================
--- NetTiers.cst (revision 711)
+++ NetTiers.cst (working copy)
@@ -57,6 +57,10 @@
<%-- 6.0 webservice --%>
<%@ Property Name="GenerateWebservice" Type="System.Boolean" Default="false" Category="06. Web - Advanced" Description="Indicates if the webservice dataaccesslayer should be generated" %>
<%@ Property Name="AttemptCreateLocalVirtualDirectory" Type="System.Boolean" Default="false" Category="06. Web - Advanced" Description="Indicates if you would like the generator to attempt to create the virtual directory for the url specified in WebServiceUrl if it doesn't exist for the WebserviceOutput directory." %>
+<%@ Property Name="PasswordProtectWebservice" Type="System.Boolean" Default="false" Category="06. Web - Advanced" Description="Indicates if the webservice should be password protected. If true then it expext the directory where the web service resides to require a username and password and optionally a domain name." %>
+<%@ Property Name="WebserviceUsername" Type="System.String" Default="" Category="06. Web - Advanced" Description="The username that will be used by the web service. Only valid if Password protection is turned on. This username will be hard coded in the WebServicesClient please make sure you have good obfuscation if you are protecting sensitive data." %>
+<%@ Property Name="WebservicePassword" Type="System.String" Default="" Category="06. Web - Advanced" Description="The password that will be used by the web service. Only valid if Password protection is turned on. This password will be hard coded in the WebServicesClient please make sure you have good obfuscation if you are protecting sensitive data." %>
+<%@ Property Name="WebserviceDomain" Type="System.String" Default="" Category="06. Web - Advanced" Description="The domain that will be used by the web service. Only valid if Password protection is turned on. This can be left blank if you're using basic authentication for your web service. Just remember that basic authentication will pass credentials in clear text." %>
<%-- 6.5 ASP.Net Website --%>
<%@ Property Name="GenerateWebsite" Type="System.Boolean" Default="true" Category="06b. Website - Advanced" Description="Indicates if a complete website should be generated." %>
@@ -1815,6 +1819,12 @@
AddFileNode(commonNode, "EntityViewProviderBase.cs");
this.GetTemplate("EntityViewProviderBaseClass.cst").SetProperty("BLLNameSpace", BLLNameSpace);
this.GetTemplate("EntityViewProviderBaseClass.cst").SetProperty("DALNameSpace", DALNameSpace);
+
+ this.GetTemplate("EntityViewProviderBaseClass.cst").SetProperty("PasswordProtectWebservice", PasswordProtectWebservice);
+ this.GetTemplate("EntityViewProviderBaseClass.cst").SetProperty("WebserviceUsername", WebserviceUsername);
+ this.GetTemplate("EntityViewProviderBaseClass.cst").SetProperty("WebservicePassword", WebservicePassword);
+ this.GetTemplate("EntityViewProviderBaseClass.cst").SetProperty("WebserviceDomain", WebserviceDomain);
+
this.RenderToFile("EntityViewProviderBaseClass.cst", rootPathDAL + "\\Bases\\EntityViewProviderBase.cs", true);
}
@@ -1977,6 +1987,7 @@
this.GetTemplate("WebService.cst").SetProperty("IncludeDelete", IncludeDelete);
this.GetTemplate("WebService.cst").SetProperty("IncludeUpdate", IncludeUpdate);
this.GetTemplate("WebService.cst").SetProperty("IncludeManyToMany", IncludeManyToMany);
+ this.GetTemplate("WebService.cst").SetProperty("PasswordProtectWebservice", PasswordProtectWebservice);
this.GetTemplate("WebService.cst").SetProperty("IncludeGetList", IncludeGetList);
this.GetTemplate("WebService.cst").SetProperty("IncludeGetListByFK", IncludeGetListByFK);
this.GetTemplate("WebService.cst").SetProperty("IncludeGetListByIX", IncludeGetListByIX);
@@ -4086,6 +4097,19 @@
System.DirectoryServices.DirectoryEntry newVirtualDirectory = rootDirectory.Children.Add(uri.Segments[uri.Segments.Length - 1], "IIsWebVirtualDir");
newVirtualDirectory.Properties["Path"].Insert(0, this.WebServiceOutputPath);
+
+ if(PasswordProtectWebservice) {
+ // Anonymous Authentication bit is 0x00000001
+ int AnonAuthBitMask = 0x11111110;
+
+ // apply bit mask to turn off anon auth
+ newVirtualDirectory.Properties["AuthFlags"].Value = Convert.ToInt32(newVirtualDirectory.Properties["AuthFlags"].Value) & AnonAuthBitMask;
+ }
+
+ newVirtualDirectory.Properties["AuthNTLM"][0] = true;
+ newVirtualDirectory.Properties["EnableDefaultDoc"][0] = true;
+ newVirtualDirectory.Properties["DefaultDoc"][0] = GetClassName(SourceDatabase) + "Services.asmx";
+
newVirtualDirectory.CommitChanges();
rootDirectory.CommitChanges();