WSE306: FramingFormatException

by Geert 9. January 2008 10:41

For one of my clients, I needed to develop a web service inside a windows service. Developing the windows service is fairly simple since I used WSE. I developed the web service so it used a soap.tcp procotol. When using a C# client, everything worked fine.

However, the client already developed a server component (let's call it broker) in C++ and gSOAP. When connecting to the web service via gSOAP (or any other 3rd party non-WSE method). One of the problems I walked into was:

WSE306: The DIME record should have the following version: 1. Instead, the DIME record contained the following version:

There are more people that are having this error, but no one seems to know the solution. So, I decided to convert the protocol to http by using the HTTP.SYS transport developed by Aaron Skonnard. This way, I was able to get more information on the error that occurred since I was able to see the exact data that was sent to the web service.

Now, I noticed that WSE was unable to send the message directly to the service, and therefore generated the exception mentioned above. The exact problem were the addressing headers. WSE requires WS-Addressing headers to be sent, but "normal" soap-messages do not contain these headers.

For gSOAP, the solution is fairly simple: read this article on how to enable WS-Addressing in gSOAP.

Now, I was able to add the required WS-Addressing headers. Finally, I was able to fix the strange (and until now unsolved) exception WSE306: FramingFormatException. It is simply because the WS-Addressing headers are missing!

The only thing for me to do now is to convert the protocol back to soap.tcp instead of http. However, the first results are bad: it seems that other tools are unable to communicatie using soap.tcp.

kick it on DotNetKicks.com

Tags:

C# | Web Services

Web Services inside Windows Services

by Geert 9. October 2007 10:58

Some time ago, a client required me to develop a Web Service and Windows Service combined. I started searching on the internet for possibilities and stumbled across this great tutorial.

I started a new Windows Service and followed all the steps in the tutorial. All compiled well and I started my Windows Service (and with that, the Web Service). However, as soon as I tried to connect to the Web Service, I received an error message "Server actively refused connection".

Let me tell a little background story about the requirements for the product. The Windows Service would run on the machine that has the IP that has a DNS entry [ServiceName].[Company].com. I wanted to start the Web Service on localhost (since I was already on the right computer).

When you try to connect to soap.tcp://localhost:[port]/[ServiceName], it will succeed. However, as soon as you try to connect to soap.tcp://[ServiceName].[Company].com/MyService, you will receive the actively refused error. When you run netstat -a, it will show you that the Web Service is listening at the right port, but why isn't it working?

The solution is that you cannot directly connect to soap.tcp://[ServiceName].[Company].com/MyService. You should first resolve the DNS entry and then connect to that result using the following code:

///  
/// Initializes the soap service listener 
///  
private void InitializeServiceListener() 
{
    try
    {
        // Create address
        string address = string.Format("soap.tcp://{0}:{1}/{2}",
        Dns.GetHostAddresses(Dns.GetHostName())[0],
        Settings.Default.ServicePort, Settings.Default.ServiceName);

        // Create SOAP listener & endpoint
        Uri addressUri = new Uri(address);

        // Start hosting the web service
        SoapReceivers.Add(new EndpointReference(addressUri), typeof(CommandListener));

        // Log
        EventLogHelper.EventLog.WriteEntry(address, EventLogEntryType.Information);
    }
    catch (Exception ex)
    {
        // Log
        EventLogHelper.EventLog.WriteEntry(string.Format(Resources.ErrorInitializingWebservice, ex.Message),
        EventLogEntryType.Error);
    }
}

As you see, you should get the hostname of the current computer to start the service. The address will be exactly the same as when you type it, but now it will work.

For the client side, you should do the same:

// Set up server
MyService server = new MyService ();
server.Url = string.Format("soap.tcp://{0}:{1}/[ServiceName]",
Dns.GetHostEntry("[ServiceName].[Company].com").AddressList[0], Settings.Default.ServicePort);

Now the Web Service inside the Windows Service will work as planned.

kick it on DotNetKicks.com

How to resolve the "Server actively refused connection" error

Tags:

C# | Web Services


About the Author

Geert van Horrik is an independent freelance software developer since January 1st, 2007. Since then he was been working on several projects from C++ to C# (WPF, Silverlight, ASP.NET, etc). Currently he loves to write his software using WPF (or Silverlight if WPF isn't an option).

Lately, Geert is spending a lot of time on Catel, a free open-source MVVM Framework for WPF and Silverlight. Actually, it's more than "just" an MVVM Framework, it's a complete application library!