[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Using Ruby Web Service from a C# .NET Client

ParappaYo

12/7/2006 12:06:00 AM

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/WebServic...

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/WebService...)]
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_st...,

RequestNamespace="http://bushidoburrito.com/WebService...,

ResponseNamespace="http://bushidoburrito.com/WebService...,

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_st...
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/envel...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
xmlns:xsd="http://www.w3.org/2001/XMLSc...><soap:Body><t...
xmlns="http://bushidoburrito.com/WebService...
/></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/XMLSc...
xmlns:env="http://schemas.xmlsoap.org/soap/envel...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...>
<env:Body>
<n1:test_stringResponse
xmlns:n1="http://bushidoburrito.com/WebService...
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/...
<return xsi:type="xsd:string">blah blah</return>
</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?

3 Answers

Jeff

12/7/2006 2:10:00 AM

0


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

Jeff
softiesonrails.com


snacktime

12/7/2006 7:21:00 AM

0

On 12/6/06, Jeff <cohen.jeff@gmail.com> wrote:
>
> 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 :-)


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.

ParappaYo

12/7/2006 7:40:00 AM

0


On 12/6/06, Jeff <cohen.jeff@gmail.com> wrote:

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

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