Using Ruby Web Service from a C# .NET Client

P

ParappaYo

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:

<code>
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
</code>

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#:

<code>
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];
}
}
}
</code>

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="http://www.w3.org/2001/XMLSchema"><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="http://www.w3.org/2001/XMLSchema"
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/">
<return xsi:type="xsd:string">blah blah</return>
</n1:test_stringResponse>
</env:Body>
</env:Envelope>
 
J

Jeff

ParappaYo said:
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 :)

Jeff
softiesonrails.com
 
S

snacktime

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 :)


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.
 
P

ParappaYo

Why not publish a REST interface instead? ....
The Soap garbage just gets in the way, in my very humble opinion :)

True enough!
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. :) 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top