Using Ruby Web Service from a C# .NET Client

I’m trying to set up a sample project of a Ruby web service consumed by
a C# .NET client. I know that lots of people have managed to use an
ASP .NET service from a Ruby client, but I am trying to do it the other
way around. To keep things super simple, I’m just trying to get the
following web service to work:

require 'soap/rpc/standaloneServer'

NS = ‘http://bushidoburrito.com/WebServiceTest

class TestStuff
def test_string()
“blah blah”
end
end

class TestServer < SOAP::RPC::StandaloneServer
def on_init
test_stuff = TestStuff.new
add_method(test_stuff, ‘test_string’)
end
end

serv = TestServer.new(‘WebServiceTest’, NS, ‘0.0.0.0’, 8080)
trap(‘INT’) { serv.shutdown }
serv.start

So far as I know, RPC::StandaloneServer doesn’t support WSDL (at least,
I couldn’t figure out how to get it), so I built my own proxy class in
C#:

using System; using System.Diagnostics; using System.Xml.Serialization; using System.Web.Services; using System.Web.Services.Protocols;

namespace WebServiceTestClient
{

[System.Web.Services.WebServiceBindingAttribute(Name=“WebServiceTestSoap”,
Namespace=“http://bushidoburrito.com/WebServiceTest”)]
public class WebServiceTestServer :
System.Web.Services.Protocols.SoapHttpClientProtocol
{
public WebServiceTestServer()
{
this.Url = “http://localhost:8080/”;
}

[System.Web.Services.Protocols.SoapDocumentMethodAttribute(“http://bushidoburrito.com/WebServiceTest/test_string”,

RequestNamespace=“http://bushidoburrito.com/WebServiceTest”,

ResponseNamespace=“http://bushidoburrito.com/WebServiceTest”,

Use=System.Web.Services.Description.SoapBindingUse.Literal,

ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string test_string()
{
object[] results = this.Invoke(“test_string”,
new object[0]);
return (string) results[0];
}
}
}

When I call the web service on the client side, the results array has a
length of 1 but results[0] is always null. I ran TcpTrace on localhost
with both the web service and the client running locally to capture the
traffic between them.

The request:

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client
Protocol 1.1.4322.2032)
Content-Type: text/xml; charset=utf-8
SOAPAction: “http://bushidoburrito.com/WebServiceTest/test_string
Content-Length: 310
Expect: 100-continue
Connection: Keep-Alive
Host: localhost:8081

<?xml version="1.0" encoding="utf-8"?><soap:Envelope

xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd=“XML Schema”>soap:Body<test_string
xmlns=“http://bushidoburrito.com/WebServiceTest
/></soap:Body></soap:Envelope>


And now the response:

HTTP/1.1 200 OK
Connection: Keep-Alive
Date: Wed, 06 Dec 2006 20:41:11 GMT
Content-Type: text/xml; charset=“utf-8”
Server: WEBrick/1.3.1 (Ruby/1.8.2/2004-12-25)
Content-Length: 494

<?xml version="1.0" encoding="utf-8" ?>

<env:Envelope xmlns:xsd=“XML Schema
xmlns:env=“http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
env:Body
<n1:test_stringResponse
xmlns:n1=“http://bushidoburrito.com/WebServiceTest
env:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/”>
blah blah
</n1:test_stringResponse>
</env:Body>
</env:Envelope>


I don’t know much about SOAP, but it seems to me that the Ruby web
service part is working just fine. Is the problem entirely with the
.NET client, then? And either way, is there anything that I can do to
fix it?

ParappaYo wrote:

I’m trying to set up a sample project of a Ruby web service consumed by
a C# .NET client. I know that lots of people have managed to use an
ASP .NET service from a Ruby client, but I am trying to do it the other
way around. To keep things super simple, I’m just trying to get the
following web service to work:

I’ve always had mixed luck trying to do soap between Ruby and .NET.
Why not publish a REST interface instead? Those are easily consumed by
.NET clients (I can post some sample code that uses a simple HttpClient
object in .NET, if that woudl help). The Soap garbage just gets in
the way, in my very humble opinion :slight_smile:

Jeff

On 12/6/06, Jeff [email protected] wrote:

Why not publish a REST interface instead? Those are easily consumed by
.NET clients (I can post some sample code that uses a simple HttpClient
object in .NET, if that woudl help). The Soap garbage just gets in
the way, in my very humble opinion :slight_smile:

He should really be using rails and actionwebservice, it makes this
much easier. We have a fairly decent sized soap api based on
actionwebservice and a number of .NET clients accessing it without any
problems. It also creates a WSDL for you which visual studio will use
without any complaints.

On 12/6/06, Jeff [email protected] wrote:

Why not publish a REST interface instead?

The Soap garbage just gets in the way, in my very humble opinion :slight_smile:

True enough!

snacktime wrote:

He should really be using rails and actionwebservice, it makes this
much easier.

Right, thanks for the tip. When I was looking into WSDL support, I
came across that, but I wanted to see if I could still do it without
Rails. I’m really only exploring this option to see if it could work,
and I’m not particularly serious about using it. :slight_smile: Mainly I was
wondering if anyone else had done this sort of thing or if there was
some SOAP guru who could point out exactly why my .NET client doesn’t
like the response that it’s getting. Of course, opinions like these on
what I should be doing instead are most welcome.