Calling web services from C#

  • Thread starter Thread starter Jon Harrop
  • Start date Start date
Jon,

In your project, right click on "references" and select "Add Web
Reference". In there, place the URL for the WSDL file, and then it should
add a file to your project which has the proxy which you can call the
getTemp method on.
 
Here is a simple web service request written in Python:

rom SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
server.getTemp('90210')

What is the most elegant way to write this in C#?

Add a Web Reference which will get you a proxy class and use that to
get to the methods easily in code.

Here's a sample from a google search I did -
http://www.codeproject.com/cs/webservices/cpwebserviceconsumer.asp

- Pramod Anchuparayil
 
Nicholas said:
What happens when you call the proxy?

For that example I get a 404. Adding a web reference to my own project seems
to autogenerate code for *CompletedEventArgs and *CompletedEventHandler but
not the actual call itself. Also, Intellisense doesn't display any useful
type information so I can't see how to invoke the RPCs.

Looking at the source code for the examples (that don't work), it seems that
adding a web reference is supposed to just generate a class with the
necessary members but that hasn't worked with the wsdl's that I've tried so
far.

I am particularly interested in examples for scientific computing. The vast
majority of this work is done on Linux, of course. Could it be that .NET
simply isn't compatible?
 
Jon said:
I am particularly interested in examples for scientific computing. The
vast majority of this work is done on Linux, of course. Could it be that
.NET simply isn't compatible?

Turns out this was correct. Most of the scientific databases are hosted on
Linux boxes and .NET is not yet compatible with them so you can't access
them from Windows.

I have managed to find a scientific database that provides a .NET compatible
SOAP interface, hosted at the European Bioinformatics Institute. Using "Add
Web Reference" works perfectly here and autogenerates ~1,000 lines of C#
code and I can use it to make RPCs from C#.

Now the only problem that I have is that the generated code escapes names
for C# and not F#, so I can't use it from F#.

Specifically, I want to do:

seq.type = "sequence";

but "type" is a reserved keyword in F#. How can I set the property
called "type" without using the identifier "type" in my code? Can I use
reflection?
 
Hi Jon,
I don't know the answer to your specific question below, but I can tell
you that there are quite a few bioinformatics web services that work with
C#. I use NCBI's stuff quite a bit
(http://www.ncbi.nlm.nih.gov/entrez/query/static/esoap_help.html) and I have
used others. If there is something specific you need to do (in C#. I have no
clue about F#), let me know and maybe I can help.
Ethan

Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)
 
Jon said:
All of the examples I've found (including this one) don't work.

Your original one does:

C:\>type ws.py
from SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
print server.getTemp('90210')

C:\>python ws.py
-999.0

C:\>wsdl /language:cs
http://www.xmethods.net/sd/2001/TemperatureService.wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Warning: This web reference does not conform to WS-I Basic Profile v1.1.
R2706: A wsdl:binding in a DESCRIPTION MUST use the value of "literal"
for the use attribute in all soapbind:body, soapbind:fault,
soapbind:header and soapbind:
headerfault elements.
- Input element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.
- Output element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.

For more details on the WS-I Basic Profile v1.1, see the specification
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.

Writing file 'C:\TemperatureService.cs'.

C:\>type ws.cs
using System;

public class Test
{
public static void Main(string[] args)
{
TemperatureService ts = new TemperatureService();
Console.WriteLine(ts.getTemp("90210"));
}
}

C:\>csc ws.cs TemperatureService.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

C:\>ws
-999

Arne
 
Jon said:
Turns out this was correct. Most of the scientific databases are hosted on
Linux boxes and .NET is not yet compatible with them so you can't access
them from Windows.

SOAP and HTTP are standards.

It does not matter whether the server is running Windows or
Linux or IBM mainframe.

It is possible to implement a standard badly, but it is
still not the operating system that is to blame then - it
is the web service toolkit used server side.

And I have personal experience for that a widely used
web service toolkit like Axis works fine with .NET

Arne
 
it is possible to call php soap webservice from c#
Here is a simple web service request written in Python:

rom SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
server.getTemp('90210')

What is the most elegant way to write this in C#?

--
Dr Jon D Harrop, Flying Frog Consultancy
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?usenet
On Thursday, July 05, 2007 12:49 PM Nicholas Paldino [.NET/C# MVP] wrote:
Jon,

In your project, right click on "references" and select "Add Web
Reference". In there, place the URL for the WSDL file, and then it should
add a file to your project which has the proxy which you can call the
getTemp method on.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

news:[email protected]...
On Thursday, July 05, 2007 1:44 PM Nicholas Paldino [.NET/C# MVP] wrote:
What happens when you call the proxy?
Your original one does:

C:\>type ws.py
from SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
print server.getTemp('90210')

C:\>python ws.py
-999.0

C:\>wsdl /language:cs
http://www.xmethods.net/sd/2001/TemperatureService.wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Warning: This web reference does not conform to WS-I Basic Profile v1.1.
R2706: A wsdl:binding in a DESCRIPTION MUST use the value of "literal"
for the use attribute in all soapbind:body, soapbind:fault,
soapbind:header and soapbind:
headerfault elements.
- Input element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.
- Output element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.

For more details on the WS-I Basic Profile v1.1, see the specification
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.

Writing file 'C:\TemperatureService.cs'.

C:\>type ws.cs
using System;

public class Test
{
public static void Main(string[] args)
{
TemperatureService ts = new TemperatureService();
Console.WriteLine(ts.getTemp("90210"));
}
}

C:\>csc ws.cs TemperatureService.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

C:\>ws
-999

Arne
 
php wsdl soap webservice can be called from c# 2.0

u need to create web service in php using nuSOAP and cann it from c# by adding it as web reference in solution explorer of visual studio
Here is a simple web service request written in Python:

rom SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
server.getTemp('90210')

What is the most elegant way to write this in C#?

--
Dr Jon D Harrop, Flying Frog Consultancy
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?usenet
On Thursday, July 05, 2007 12:49 PM Nicholas Paldino [.NET/C# MVP] wrote:
Jon,

In your project, right click on "references" and select "Add Web
Reference". In there, place the URL for the WSDL file, and then it should
add a file to your project which has the proxy which you can call the
getTemp method on.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

news:[email protected]...
On Thursday, July 05, 2007 1:44 PM Nicholas Paldino [.NET/C# MVP] wrote:
What happens when you call the proxy?
Your original one does:

C:\>type ws.py
from SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
print server.getTemp('90210')

C:\>python ws.py
-999.0

C:\>wsdl /language:cs
http://www.xmethods.net/sd/2001/TemperatureService.wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Warning: This web reference does not conform to WS-I Basic Profile v1.1.
R2706: A wsdl:binding in a DESCRIPTION MUST use the value of "literal"
for the use attribute in all soapbind:body, soapbind:fault,
soapbind:header and soapbind:
headerfault elements.
- Input element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.
- Output element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.

For more details on the WS-I Basic Profile v1.1, see the specification
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.

Writing file 'C:\TemperatureService.cs'.

C:\>type ws.cs
using System;

public class Test
{
public static void Main(string[] args)
{
TemperatureService ts = new TemperatureService();
Console.WriteLine(ts.getTemp("90210"));
}
}

C:\>csc ws.cs TemperatureService.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

C:\>ws
-999

Arne
 
php wsdl soap webservice can be called from c# 2.0

u need to create web service in php using nuSOAP and cann it from c# by adding it as web reference in solution explorer of visual studio
Here is a simple web service request written in Python:

rom SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
server.getTemp('90210')

What is the most elegant way to write this in C#?

--
Dr Jon D Harrop, Flying Frog Consultancy
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?usenet
On Thursday, July 05, 2007 12:49 PM Nicholas Paldino [.NET/C# MVP] wrote:
Jon,

In your project, right click on "references" and select "Add Web
Reference". In there, place the URL for the WSDL file, and then it should
add a file to your project which has the proxy which you can call the
getTemp method on.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

news:[email protected]...
On Thursday, July 05, 2007 1:44 PM Nicholas Paldino [.NET/C# MVP] wrote:
What happens when you call the proxy?
Your original one does:

C:\>type ws.py
from SOAPpy import WSDL
wsdlFile = 'http://www.xmethods.net/sd/2001/TemperatureService.wsdl'
server = WSDL.Proxy(wsdlFile)
print server.getTemp('90210')

C:\>python ws.py
-999.0

C:\>wsdl /language:cs
http://www.xmethods.net/sd/2001/TemperatureService.wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Warning: This web reference does not conform to WS-I Basic Profile v1.1.
R2706: A wsdl:binding in a DESCRIPTION MUST use the value of "literal"
for the use attribute in all soapbind:body, soapbind:fault,
soapbind:header and soapbind:
headerfault elements.
- Input element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.
- Output element soapbind:body of operation 'getTemp' on portType
'TemperatureBinding' from namespace
'http://www.xmethods.net/sd/TemperatureService.wsdl'.

For more details on the WS-I Basic Profile v1.1, see the specification
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.

Writing file 'C:\TemperatureService.cs'.

C:\>type ws.cs
using System;

public class Test
{
public static void Main(string[] args)
{
TemperatureService ts = new TemperatureService();
Console.WriteLine(ts.getTemp("90210"));
}
}

C:\>csc ws.cs TemperatureService.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

C:\>ws
-999

Arne
 
php wsdl soap webservice can be called from c# 2.0

u need to create web service in php using nuSOAP and cann it from c# by adding it as web reference in solution explorer of visual studio

There are other possibilities than nuSOAP.

But do you really think that Jon Happrop or any other
participants in this thread is stil waiting for suggestions
3 years after??

Arne
 
Back
Top