Call external web service

J

John Straumann

Hello all:

I am working on a C# program and I need to invoke a method on an external
web service. I have done many such method invocations from .NET web services
where I am able to add the web reference to my project, but for this all I
have is a WSDL and the URL for the external service.

Can anyone give me some insight as to how I create an object for the
external web service and then pass the data I need to send to it?

Thanks for any and all help.

John.
 
J

John Straumann

Thanks for the note. I tried that and got the errors as shown below.

Is there no easy way to create an object, passing in the URL as a parameter
from which I can then call the methods?

John.
 
M

Marc Gravell

For testing, I'm using the standard "ASP.NET Web Service Application"
project template. My wsdl is then:
http://localhost:1471/Service1.asmx?wsdl
Which I have saved to a local file "my.wsdl"

Note I'm only using this as an example of a standalone wsdl file and a
url.

I've then gone to the VS cmd prompt:
wsdl d:\my.wsdl /urlkey:myurl

which generates Service1.cs

Now add a new console application and add Service1.cs and add a
reference to System.Web.Services and System.Configuration

Add -> app.config
Edit app.config to include:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="myurl" value="http://localhost:1471/Service1.asmx"/>
</appSettings>
</configuration>

Finally, edit Program.cs to use the web-service, and execute:

using System;
class Program
{
static void Main()
{
using (Service1 svc = new Service1())
{
Console.WriteLine(svc.HelloWorld());
}
}
}
 
J

John Straumann

Oops, forgot the errors did I?! :)

Here they are:

C:\Temp>wsdl /out:myproxyclass.cs
http://srv019v:9000/test/iWayCallout.ibs?wsdl
Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: There was an error processing
'http://srv019v:9000/test/iWayCallout.ibs?wsdl'.
- The document at the url http://srv019v:9000/test/iWayCallout.ibs?wsdl
was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'DISCO Document' is 'Discovery document at the URL
http://srv019v:9000/test/iWayCallout.ibs?wsdl could not be found.'.
- The document format is not recognized.
- Report from 'WSDL Document' is 'There is an error in XML document (1,
3357).'.
- The element was not expected in this context: <xs:simpleType
xmlns:xs='http://www.w3.org/2001/XMLSchema'>..</xs:simpleType>. Expected el
ements: http://www.w3.org/2001/XMLSchema:annotation,
http://www.w3.org/2001/XMLSchema:element,
http://www.w3.org/2001/XMLSchema:sequence, ht
tp://www.w3.org/2001/XMLSchema:any, http://www.w3.org/2001/XMLSchema:choice,
http://www.w3.org/2001/XMLSchema:group.
- Report from 'XML Schema' is 'The root element of a W3C XML Schema should
be <schema> and its namespace should be 'http://www.w3.org/2001/X
MLSchema'.'.
If you would like more help, please type "wsdl /?".
 
M

Marc Gravell

It begs the question of whether their wsdl is well formed. I don't
know enough about wsdl to answer off the top of my head... but from
the error it certainly isn't what wsdl.exe is expecting. Hard to tell
without visibility of the wsdl, unfortunately...

Marc
 

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

Top