What's wrong with this config transform? - visual-studio-2010

I have the following part of a web.base.config:
<system.serviceModel>
<client>
<!-- Reporting Services -->
<endpoint name="ReportExecutionEndpoint" address="http://~MACHINENAMEREPLACEMENTTOKEN~/ReportServer/ReportExecution2005.asmx" binding="basicHttpBinding" behaviorConfiguration="AuthenticatedBehavior" bindingConfiguration="ReportingServicesConfiguration" contract="ReportingWebService.ReportExecutionServiceSoap" />
<!-- Custom Services -->
<endpoint name="Blah1Endpoint" address="net.tcp://~MACHINENAMEREPLACEMENTTOKEN~/DomainServices/blah1.svc" binding="netTcpBinding" behaviorConfiguration="AuthenticatedBehavior" bindingConfiguration="LargerMessagesConfiguration" contract="Fully.Qualified.IBlah1" />
<endpoint name="Blah2Endpoint" address="net.tcp://~MACHINENAMEREPLACEMENTTOKEN~/DomainServices/blah2.svc" binding="netTcpBinding" behaviorConfiguration="AuthenticatedBehavior" bindingConfiguration="LargerMessagesConfiguration" contract="Fully.Qualified.IBlah2" />
<endpoint name="Blah3Endpoint" address="net.tcp://~MACHINENAMEREPLACEMENTTOKEN~/DomainServices/blah3.svc" binding="netTcpBinding" behaviorConfiguration="AuthenticatedBehavior" bindingConfiguration="LargerMessagesConfiguration" contract="Fully.Qualified.IBlah3" />
</client>
</system.serviceModel>
I want to add an <identity><dns /></identity> in for all of the CustomServices but not the ReportingServices. To do so, I have the following transform segment:
<system.serviceModel>
<client>
<endpoint xdt:Locator="Condition(contains(#address, 'net.tcp'))">
<identity xdt:Transform="Insert">
<dns value="~MACHINENAMEREPLACEMENTTOKEN~" />
</identity>
</endpoint>
</client>
</system.serviceModel>
The problem is that this only does so for the first CustomService but not all of the others (although it correctly skips the ReportingServices). How can I change this transform so it hits all of my CustomServices endpoints?

The way that the Insert transform is designed is for single use. Because of this it will insert only the first match.
A workaround for you in this case would be to create an Insert transform for each net.tcp endpoint.
If you really need to get this done, you can create your own custom transform which can insert for multiple matches. I have blogged about how to do that at
http://sedodream.com/2010/09/09/ExtendingXMLWebconfigConfigTransformation.aspx.

Related

WCF Service, the type provided as the service attribute values...could not be found

I have this issue a long time ago and just cannot recall how to resolve it or perphaps its something new. I created a WCF service which I will later use in web application that calls the WCF service amongst others from a remote location. Right now I am trying to host in IIS and even tried the WCFTestClient. The error I get when I try to browse to the service; is the following:
The type MyService.Service1 provided as the Service attribute
value in the ServiceHost directive, or provided in the
configuration element system.serviceModel/serviceHostingEnvironment/
serviceActivations could not be found.
I figured its probably my web.config file but I cannot see whats wrong:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" crossDomainScriptAccessEnabled="false" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="WcfInstanceRules2.Service1">
<endpoint address=""
binding="webHttpBinding"
contract="WcfRules2.IServiceS" behaviorConfiguration="web"/>
<endpoint address="mex"
binding="webHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
I would like this to be eventually a rest service delivering data in json format.
Check your .svc file and see what service it's referencing - probably MyService.Service1, which doesn't exist in your config. It looks like it should be referencing WcfInstanceRules2.Service1.

wcf service no config file when adding service reference

I have a wcf service that I tried to add using both svcutil and by adding service reference to the client test project. In both cases a new config file was not created and subsequently the client test will not run due to it not seeing the endpoints. Why is this the case and here is my web.config file for the WCF service.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="WcfInstanceRules2.Service1">
<endpoint address=""
binding="webHttpBinding" bindingConfiguration="webHttpBinding"
contract="WcfInstanceRules2.IService1"
behaviorConfiguration="web"/>
</service>
</services>
If you're using the webHttpBinding then you're writing a RESTful service, right? REST services aren't "consumed" via Visual studio or via SvcUtil.exe like other SOAP based services (for example, that would use a SOAP based binding like basicHttpBinding, or wsHttpBinding etc). You would "consume" the service by calling it from something like jQuery:
$.getJSON("Service1.svc/uriTemplateNameHere", { param: myParameter },
function (result) {
// do something
});
Can you post your WCF code?

Getting HTTPS to Work with WCF and a Windows Service

I tried updating the App.config files for the client and service for the MS sample applications in WF_WCF_Samples\WCF\Basic\Services\Hosting\WindowsService\CS\WindowsService.sln so that secure bindings were used but when the client makes the call to the service method an exception is thrown
"An error occurred while making the HTTP request to https:// .... /servicemodelsamples/service. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server."
Inner exception "The underlying connection was closed: An unexpected error occurred on a send"
As far as I can see both the server and client configs match and use Transport security mode and the mex endpoint now uses mexHttpsBinding rather than mexHttpBinding with the service behaviour appropriately enabled.
Can someone tell me what is missing or incorrect as I have tried numerous tweaks with no success?
Thanks
The server and client configs are
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.Samples.WindowsService.WcfCalculatorService">
<host>
<baseAddresses>
<add baseAddress="https://localhost:8000/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<!-- This endpoint is exposed at the base address provided by host: https://localhost:8000/ServiceModelSamples/service -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="https" contract="Microsoft.Samples.WindowsService.ICalculator"/>
<!-- The mex endpoint is exposed at https://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
<binding name="https">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<!-- For debugging purposes set the includeExceptionDetailInFaults attribute to true -->
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
and
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<client>
<endpoint name="" address="https://localhost:8000/servicemodelsamples/service" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.Samples.WindowsService.ICalculator"/>
</client>
<bindings>
<basicHttpBinding>
<!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
<binding name="Binding1">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
mex cant be https
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
change to
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

Do I need to do anything special to make WCF calls work over HTTPS, ..if HTTP works fine?

I have two versions of the same proof-of-concept site: The unsecure version:
http://www.tlsadmin.com/tlsadmin/PortalHome.aspx
and the secure version:
https://www.tlsadmin.com/tlsadmin/PortalHome.aspx
The problem I have is that my WCF-Based web services don't seem to work under HTTPS. Is there something I'm missing, or not understanding about this? I thought a relative URL for the SVC file would cover everything
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services>
<asp:ServiceReference Path="~/Services/Contacts.svc" />
<asp:ServiceReference Path="~/Services/Domains.svc" />
<asp:ServiceReference Path="~/Services/TreeViewNavigation.asmx" />
<asp:ServiceReference Path="/Services/FullSoaSchedulerService.svc/json" />
</Services>
</asp:ScriptManager>
Perhaps I need to add an additional binding for the webservice to work over HTTPS?
<service name="LC.www.nexthop.mx.POC.grid_WebService.Domains">
<endpoint address="" behaviorConfiguration="LC.www.nexthop.mx.POC.grid_WebService.DomainsAspNetAjaxBehavior"
binding="webHttpBinding" contract="LC.www.nexthop.mx.POC.grid_WebService.Domains" />
</service>
You want to add a custom binding to your configuration to enable it for HTTPS by setting your binding's security mode to transport.
<bindings>
<webHttpBinding>
<binding name="httpsBinding">
<security mode="Transport">
</security>
</binding>
</webHttpBinding>
</bindings>
The default security mode is None which doesn't play well with HTTPS.
Then assign that binding to your endpoint:
<service name="LC.www.nexthop.mx.POC.grid_WebService.Domains">
<endpoint address="" behaviorConfiguration="LC.www.nexthop.mx.POC.grid_WebService.DomainsAspNetAjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpsBinding" contract="LC.www.nexthop.mx.POC.grid_WebService.Domains" />
</service>
This blog post helped me out when I first ran into this situation.
Hope this helps!!

Why do I need to rebuild a WCF AJAX Service that didn't change while debugging?

I have a WCF based service that I use to expose AJAX functionality. Sometimes the service fails when I start a new debugging session (even if I make no changes to the service itself). A rebuild all fixes the issue. I never have this issue in production, just while debugging. I use IIS 7 to debug and have disabled all recycling. Below is my config.
Does anyone know why this happens? Is there another way I can configure the service?
Thanks!
Jon
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SomeService.MyAjaxServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="SomeService.MyAjaxService">
<endpoint address="" behaviorConfiguration="SomeService.MyAjaxServiceAspNetAjaxBehavior" binding="webHttpBinding"
bindingConfiguration="webBinding"
contract="SomeService.MyAjaxService" />
<endpoint address="" behaviorConfiguration="SomeService.MyAjaxServiceAspNetAjaxBehavior" binding="webHttpBinding"
bindingConfiguration="sslWebBinding"
contract="SomeService.MyAjaxService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="sslWebBinding">
<security mode="Transport">
</security>
</binding>
<binding name="webBinding">
<security mode="None">
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
I ended up having to add batch="false" in the web config. I still need to investigate the full ramifications of this, but at least I don't have to rebuild the service all the time.
Cheers,
Jon

Resources