Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Call external web service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Straumann - 18 Mar 2008 20:36 GMT
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.
Marc Gravell - 18 Mar 2008 21:21 GMT
Track down wsdl.exe (or wse3wsdl.exe or svcutil.exe); easiest way is
to use the "Visual Studio <version> Command Prompt" shortcut.

Then just pass "your.wsdl" as an argument. You can supply other
arguments to customize it - use /? or look on MSDN.

http://msdn2.microsoft.com/en-us/library/7h3ystb6(VS.80).aspx

Marc
John Straumann - 18 Mar 2008 21:43 GMT
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.

> Track down wsdl.exe (or wse3wsdl.exe or svcutil.exe); easiest way is
> to use the "Visual Studio <version> Command Prompt" shortcut.
[quoted text clipped - 5 lines]
>
> Marc
Marc Gravell - 18 Mar 2008 21:54 GMT
> I tried that and got the errors as shown below.

Which errors?
John Straumann - 19 Mar 2008 00:13 GMT
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 /?".

>> I tried that and got the errors as shown below.
>
> Which errors?
Marc Gravell - 19 Mar 2008 07:49 GMT
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
Marc Gravell - 18 Mar 2008 22:03 GMT
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());
       }
   }
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.