开发者

Consuming an XML web service in .NET 4.0

I'm attempting to use a web service from this site: http://www.averittexpress.com/services/technology/webservices.html

The web service I'm trying to use is the very first one on the page: http://webservices.averittexpress.com/TransitTimeService

I've never consumed a web service before, so I'm not sure where to start. I've done searches, but all the articles and blog posts that come up are nearly 10 years old.

I tried adding a web reference to my project in Visual Studio and entering the service url, but I just got an error.

Can someone lead me in the right direction?

EDIT:

Error message:

The HTML document does not contain Web service discovery information. There was an error downloading 'http://webservices.averittexpress.com/TransitTimeService/$metadata'. The request failed with HTTP status 404: Not Found.

EDIT 2:

I used http://webservices.averittexpress.com/TransitTimeService?WSDL when adding a web reference. XML loaded in the preview window, but I still received these errors:

*The document was understood, but it could not be processed. - The WSDL document contains links that could not be resolved. - There was an error downloading 'http://webservices.averittexpress.com/TransitTimeService/TransitTimeService_schema1.xsd'. - The request failed with HTTP status 404: Not Found.*

And these lines are highlighted red in the preview window:

<definitions name="TransitTimeService"
    targetNamespace="http://webservices.averittexpress.com/TransitTimeService"
    xmlns="http://schemas.xmlsoap.org/wsdl/" <!-- highlighted red -->
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" &l开发者_C百科t;!-- highlighted red -->
    xmlns:tns="http://webservices.averittexpress.com/TransitTimeService" <!-- highlighted red -->
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <!-- highlighted red -->


The URL you gave has all the info

http://www.averittexpress.com/services/technology/webservices.html

Including the correct location of the WSDL

http://www.averittexpress.com/services/technology/wsdl/TransitTimeService.wsdl

The location of the schema file is also there its

http://www.averittexpress.com/services/technology/wsdl/TransitTimeService_schema1.xsd


Use the following URL: http://webservices.averittexpress.com/TransitTimeService?WSDL

You can either import the WSDL as a web reference, or you can create the proxy by hand by doing the following:

  • Open a Visual Studio command prompt (Start > Visual Studio 2010 > Visual Studio Command Prompt)
  • cd to your code directory
  • svcutil http://webservices.averittexpress.com/TransitTimeService?WSDL, should generate a client proxy called TransitTimeService.cs or something similar.
  • See the svcutil documentation for customizing the output file to your needs.


When you're wanting to create a web or service reference, you will need the WSDL for the web service. For most standard web services, you can get to the service's WSDL by appending a ?wsdl to the end of the base URL like this:

http://webservices.averittexpress.com/TransitTimeService?wsdl

In this case, the URL above redirects to this:

http://webservices.averittexpress.com/TransitTimeService/TransitTimeService.wsdl

You should be able to use either of these to generate a web or service reference. However, in this particular case, there is a file referenced in the TransitTimeService.wsdl that does not seem to exist on that server: TransitTimeService_schema1.xsd. When I tried to create a service reference for that WSDL, I got a 404 saying that the schema file does not exist. The URL below is where the schema should be, but it's not there, so you may not be able to easily generate a reference for this service.

http://webservices.averittexpress.com/TransitTimeService/TransitTimeService_schema1.xsd

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜