WCF service for Cold Fusion client: undefined portType in WSDL

We have been helping a company consume our WCF services from Cold Fusion. I was surprised when a relatively simple WCF service caused an exception in the Cold Fusion 9 cfinvoke tag. The error message stated that there was an undefined portType in WSDL.

To solve the issue, declare a namespace in the ServiceBehavior attribute of your WCF service and leave the namespace empty in the ServiceContract attribute:

[ServiceContract]
[ServiceBehavior(Namespace = "http://yourdomainname.com/")]

Happy coding!

WCF service with Named Pipe Binding on multiple sites in IIS7

A named pipe is a system kernel object that processes on the same server may use for communicating with each other. It is a fast, secure, and reliable way for your applications to access on-machine WCF services.

While working on the test server that hosted multiple sites in IIS7 (test, uat, staging, etc.), I have noticed that for a single web service all sites used the same named pipe - you can look at all named pipes defined on your system using a tool like PipeList. Needless to say, reusing the same named pipe is not a desirable behavior in this situation.

I looked closer into the issue. From what I now understand, WCF uses an algorithm that maps a service path to the pipe name. By default, this algorithm ignores the domain name of the site and, thus, all sites on the server map services with the same local path to the same named pipes.

That explain the root cause of the issue. How can we get it fixed? How can we force the algorithm to take the domain name into acount when creating a named pipe?


The first step is to set the hostNameComparisonMode attribute to Exact in the NetNamedPipeBinding configuration of your service:

<netNamedPipeBinding>

    <binding  name="YourNamedPipeBinding"  hostNameComparisonMode="Exact" />

</netNamedPipeBinding>


The second step is to modify the net.pipe binding on each IIS7 website:

Named Pipe Binding Information


Hope it helps. Happy coding!

October book review: Essential WCF

Steve Resnick, Richard Crane, Chris Bowen
Essential Windows Communication Foundation. For .NET Framework 3.5.

This is a well-organized and easy-to-read introductory book on WCF. It provides a thorough overview of the principles behind building and consuming WCF web services and includes real-world examples illustrating how to leverage WCF framework in your applications. The topics covered in this book include:

  • Contracts: how to define complex structures and interfaces
  • Channels: how to configure channels and channel stacks
  • Bindings: how to choose communication protocols
  • Behaviors: how to manage instances, concurrency, and transactions as well as how to add your own custom behaviors
  • Serialization and Encoding: how .NET classes are serialized and represented on the wire
  • Hosting services in IIS, WAS, and managed .NET applications
  • Security options for authentication and transport- and message-level security for Internet and Intranet applications
  • Integration with other frameworks such as WF and Silverlight
  • Other topics: JSON, RSS/ATOM, peer networking, metadata publishing, diagnostics, and others
    • The authors did an excellent job explaining complex WCF concepts in simple terms and will help you jump right into building distributed applications in .NET. I highly recommend this book to .NET application developers and architects.

      Happy reading!

How to call MapPath in WCF services

While working with WCF services hosted in IIS7 with non-HTTP endpoints (such as TCP or NamedPipes), we realized that our usual way to resolve a phisycal file path corresponding to a virtual path on the web server is not supported.

In ASP.NET, we use HttpContext.Current.Server.MapPath method, but HttpContext.Current is null in WCF services with non-HTTP endpoints. What shall we do? It turns out that there is another way to map a virtual path: using the HostingEnvironment class. See the example below.

public static string MapPath(string path)
{

    if (HttpContext.Current != null)

        return HttpContext.Current.Server.MapPath(path);

    return HostingEnvironment.MapPath(path);

}

Happy coding!

.NET 3.5, WCF, JSON, SSL, and HTTP Error Code 401

We run into an interesting problem today at work while working with JSON WCF Web Services built with Visual Studio 2008 and .NET 3.5.

The web application we are working on is to be released in a couple of weeks. It has been running fine on the test server for a number of iterations now, but today we installed an SSL certificate on this server and configured the application to require secure channel. Suddenly, the web application started to ask us for a username and password...

I looked closer into the logs and noticed the HTTP Error Code 401 (authorization error) coming back from web services when the web application requested our java script proxies. It turns out that in order to allow communication with the services via SSL, you need to configure additional binding configuration. See below our sample service model configuration. Hope it will save you a few hours of troubleshooting. 

<system.serviceModel>
    <behaviors
>
        <endpointBehaviors>
            <
behavior name="jsonBehavior">
                <enableWebScript />
            </
behavior>
        </endpointBehaviors>  

        <
serviceBehaviors>
            <behavior name="myServiceBehavior"
>
                <
serviceMetadata httpGetEnabled="true" httpGetUrl="" />  
                <serviceDebug includeExceptionDetailInFaults="true"
/>
                <serviceThrottling maxConcurrentCalls="100"
                                          maxConcurrentInstances="1000"
                                          maxConcurrentSessions="1000"/>
 
            </behavior
>
        </
serviceBehaviors> 
    </behaviors
>  

    <
bindings> 
        <webHttpBinding
>
            <
binding name="sslBinding"> 
                <security mode="Transport"
/>
            </
binding>
        </webHttpBinding> 
    </
bindings>  

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
/>
        <
services> 
            <service behaviorConfiguration="myServiceBehavior"
 
                        name="CourseCatalog"

            
<endpoint contract="CourseCatalog"
                               address=""
                               behaviorConfiguration="jsonBehavior"
                               binding="webHttpBinding"
                               bindingConfiguration="sslBinding"/>
 
                <endpoint contract="IMetadataExchange
                               address="mex
                               binding="mexHttpBinding" />
  
            </service>
 
    </services

</system.serviceModel>

Happy coding!

Welcome to ModelBlog

Thank you for visiting ModelBlog. We hope the time you spend with us will be both entertaining and worth your while. Have fun!

Authors

Search

Archive

Tags