Update site bindings in applicationHost.config - binding

I am trying to add a list of site bindings to the applicationHost.config file as opposed to manually adding each one through IIS 7.5.
<site name="new_site" id="6">
<application path="/" applicationPool="new_site">
<virtualDirectory path="/" physicalPath="D:\HTTP\wwwroot\newsite" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:example.com" />
<binding protocol="http" bindingInformation="*:80:www.example.com" />
<binding protocol="http" bindingInformation="*:80:example2.com" />
<binding protocol="http" bindingInformation="*:80:www.example2.com" />
</bindings>
</site>
The reason for doing this is i have 2000 bindings to add, which would be a lot easier to do if i could edit the config file directly.
When editing the config file however the bindings do not work or show up in IIS.
Is this actually possible or am i missing something?

You could script this in PowerShell:
[Reflection.Assembly]::Load(
"Microsoft.Web.Administration, Version=7.0.0.0,
Culture=Neutral, PublicKeyToken=31bf3856ad364e35") > $null
$siteId = 6
$serverManager = New-Object Microsoft.Web.Administration.ServerManager
$site = $serverManager.Sites | where { $_.Id -eq $siteID }
# Read your list of hostnames
$reader = [System.IO.File]::OpenText("c:\\hostnames.txt")
for(;;)
{
$domainName = $reader.ReadLine()
if($domainName -eq $null) { break }
$binding1 = "*:80:www." + $domainName
$binding2 = "*:80:" + $domainName
$site.Bindings.Add($binding1, "http")
$site.Bindings.Add($binding2, "http")
}
$serverManager.CommitChanges()
The file c:\\hostnames.txt would contain a list of all your domain names, for example:
domanname1.com
domanname2.com
domanname3.com
If you need to bind to a specific IP address then replace * with the IP address.

You should use Microsoft.Web.Administration assembly and create sites trough that API. Here is the example of creating a site
http://learn.iis.net/page.aspx/226/microsoftwebadministration/

Are you using a 32-bit editor on a 64 bit machine? If so, Windows is saving your edits to C:\Windows\SysWOW64\inetsrv\Config\applicationHost.config.
See https://serverfault.com/questions/315904/cannot-open-iis-7-applicationhost-config-in-64-bit-windows-with-32-bit-text-edit

Related

Facing issue while consuming services from a class library in a API project

I have created a Class library project and add the service reference of "E-Verify" web service to this project. In this project, I have created a wrapper class and consumed all the services of "E-Verify".
I have added the reference to this project in the API project. But, while assessing this wrapper method inside an API project I am getting an error
Error:
Could not find default endpoint element that references contract 'EmployerWebServiceV29.IEmployerWebServiceV29' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Anyone having any idea how to fix this issue?
Wrapper Code:
try {
EmployerWebServiceV29Client client = new EmployerWebServiceV29Client();
client.ClientCredentials.UserName.UserName = "";
client.ClientCredentials.UserName.Password = "";
client.VerifyConnection();
} catch (Exception ex) {
throw new ServiceAccessException(ErrorConstants.SERVICE_ACCESS_ERROR);
}
app.config:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IEmployerWebServiceV29">
<security mode="TransportWithMessageCredential"/>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="CustomBinding_IEmployerWebServiceV29">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None"/>
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="stage.e-verify.uscis.gov/WcfWebService/…;"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IEmployerWebServiceV2‌​9"
contract="EmployerWebServiceV29.IEmployerWebServiceV29"
name="BasicHttpBinding_IEmployerWebServiceV29"/>
<endpoint address="stage.e-verify.uscis.gov/WcfWebService/…;"
binding="wsHttpBinding"
bindingConfiguration="CustomBinding_IEmployerWebServiceV29"
contract="EmployerWebServiceV29.IEmployerWebServiceV29"
name="CustomBinding_IEmployerWebServiceV29"/>
</client>

web.config transform not working

In an MVC application I have a web.config that is setup for my development environment, and I have a transform file that needs to insert a new WCF service endpoint, however it is adding it in the wrong place so I think I have missed something.
I have cut down on the config file to show only what is needed.
I have the normal web.config as follows:
<services>
<!-- Report Service -->
<service name="Core.ReportDataHost">
<endpoint name="ReportDataHost" address="..." binding="customBinding" contract="..."/>
</service>
<!-- Authentication Service -->
<service name="Core.AuthenticationHost">
<endpoint name="AuthenticationHost" address="..." binding="customBinding" contract="..."/>
</service>
</services>
I then have the transform file as follows:
<services>
<service name="Core.AuthenticationHost">
<endpoint xdt:Transform="Insert" address="" binding="customBinding" contract="..." />
</service>
</services>
I expected this to add the new endpoint in the "AuthenticationHost" service, but it adds it to the first service "ReportDataHost".
Any ideas what I am missing?
Transforms only use tags by default, not attributes, so even though you have name="Core.AuthenticationHost" in your transform, it is being ignored and only matching on the Service tag, using the first Service tag it finds.
Add a locator to the <service> tag so that it knows which one to use (instead of just using the first). The Locator is an attribute on the tag: xdt:Locator="Match(attribute1,attribute2,...)". In this case, you want to match on the name attribute.
Your corrected Transform will look like this:
<services>
<service name="Core.AuthenticationHost" xdt:Locator="Match(name)">
<endpoint xdt:Transform="Insert" address="" binding="customBinding" contract="..." />
</service>
</services>
More information is available on MSDN's Transform Syntax page.

TCP Federation and ADFS

I hope someone can help me out. How can I do federation over TCP? I am using ADFS as my STS. My WCF service (Relying party) expose its endpoint over net.tcp bindings. The STS would be accessed through wsHttp endpoints. How would I do this? Any suggestions?
Thank you
I am just wondering if I am doing this correctly. I have created a custom binding. This is for the server side.
<!-- STS Binding -->
<ws2007HttpBinding>
<binding name="STSBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="false"/>
</security>
</binding>
</ws2007HttpBinding>
<customBinding>
<binding name="WCFTestServiceLibrary.IService1_FederationNetTcpBinding">
<security authenticationMode="SecureConversation" requireSecurityContextCancellation="true">
<secureConversationBootstrap authenticationMode="IssuedToken">
<issuedTokenParameters tokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile- 1.1#SAMLV2.0">
<issuer address="https://test/adfs/services/trust/13/issuedtokenmixedasymmetricbasic256"
binding="ws2007HttpBinding" bindingConfiguration="STSBinding">
</issuer>
<issuerMetadata address="https://test/adfs/services/trust/mex" />
<claimTypeRequirements>
<add claimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" isOptional="true" />
<add claimType="http://schemas.microsoft.com/ws/2008/06/identity/claims/role" isOptional="true" />
</claimTypeRequirements>
</issuedTokenParameters>
</secureConversationBootstrap>
</security>
<binaryMessageEncoding />
<tcpTransport />
</binding>
</customBinding>
Never done this but from what I've read:
Check that your endpoint is enabled in ADFS.
Then add tcp to the "Enabled Protocols" for the ADFS IIS site.
Refer Enabling net.tcp

Why Project Not Build in Azure One Web Role for Multiple Website setup?

I got 1 Azure web role for multiple websites, and it worked, the code in "ServiceDefinition.csdef" looks like:
<Sites>
<Site name="SiteA" physicalDirectory="..\SiteA">
<Bindings>
<Binding name="HttpBinding" endpointName="HttpEndpoint" hostHeader="a.com" />
</Bindings>
</Site>
<Site name="SiteB" physicalDirectory="..\SiteB">
<Bindings>
<Binding name="HttpBinding" endpointName="HttpEndpoint" hostHeader="b.com" />
</Bindings>
</Site>
<Site name="SiteC" physicalDirectory="..\SiteC">
<Bindings>
<Binding name="HttpBinding" endpointName="HttpEndpoint" hostHeader="c.com" />
</Bindings>
</Site>
</Sites>
A, B, C all works.
but the situation is, A, B, C are projects, need to build ( as release ) to get them work well.
What Azure tool (in Visual Studio) does is just simply copy them (the folder) not build them ( as release). The result is, all files on server, even MVC patten works, but the Web.Release.config does not replace(a part of) Web.config, so some codes not work.
My question is, how to setup Azure support multiple projects, and build them as release, in one web role?

How to consume a webservice in MVC?

I am super new to MVC (in fact, this is my first assignment)
So, I have a good webservice running, functional, on my local machine
http://www.codetrials.local/wcf/UserServices.svc?wsdl
and In my MVC application, I added a service reference as usual, and then in my Model.cs I am trying this:
using (CodeTrials.UserServicesClient _client = new UserServicesClient())
{
UserWebsite = _client.GetUserWebsite(username);
}
but when I try to run this, I always get the exception endpoint not found. I can access this from my (different) asp.net project and it works just fine, same code and everything. After some digging around I found this answer I modified my above code to:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://www.codetrials.local/wcf/UserServices.svc");
using (CodeTrials.UserServicesClient _client = new UserServicesClient(binding, address))
{
UserWebsite = _client.GetUserWebsite(username);
}
but now, I get a new exception: There was no endpoint listening at http://www.codetrials.local/wcf/UserServices.svc?wsdl that could accept the message
So I am at my wits end.
I found a similar question but it's not what I am looking for.
Can you please guide me to the right path?
what am I not doing right?
should I shift the consuming of webservice from Model to Controller?
Thanks.
EDIT - This is my config file system.serviceModel section. I just copy pasted it from the WCF client test gui tool into web.config since it was not being generated by visual studio.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IUserServices" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.codetrials.local/wcf/UserServices.svc/wcf/UserServices.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserServices"
contract="IUserServices" name="BasicHttpBinding_IUserServices" />
</client>
</system.serviceModel>
Reposting from the comments since it turned out to be the answer. :) Turned out that web.debug.config was overwriting the web.config in this case.
Are you sure its in the right web.config then? VS should create it automatically when you add the service reference (it does for me at least). One gotcha is that a normal MVC app has two web.config files, there's a second one inside the Views folder by default. Other then that, I'm not really sure whats going on.
Your code shows you are using this URL: http://www.codetrials.local/wcf/UserServices.svc to access the service endpoint but your exception message says you are actually using http://www.codetrials.local/wcf/UserServices.svc?wsdl instead.
Check your MVC app web.config file for a serviceModel element. If you need to configure the WCF client in code then remove that entire element from the web.config file which may be where the wrong URL is coming from. If you do want to configure WCF from the web.config file, then remove your current code and use the following two lines to create the client and invoke the service:
var _client = new UserServicesClient("BasicHttpBinding_IUserServices");
UserWebsite = _client.GetUserWebsite(username);
where the something like the following section exists in your web.config serviceModel element:
<system.serviceModel>
<client>
<endpoint
name="BasicHttpBinding_IUserServices"
address="http://www.codetrials.local/wcf/UserServices.svc"
binding="basicHttpBinding"
contract="IUserServices" >
</endpoint>
</client>
<!-- rest of element snipped -->
Finally, you should not wrap the UserServicesClient instantiation in a using statement because of the reasons outlined in this post. WCF is a tricksty beast....
EDIT:
Based on the update with your config, your problem may be that the service URL is:
http://www.codetrials.local/wcf/UserServices.svc/wcf/UserServices.svc
The wcf/UserServices.svc seems to be duplicated.

Resources