【问题标题】:C# ASP.Net adding online web serviceC# ASP.Net 添加在线 Web 服务
【发布时间】:2014-12-05 21:25:32
【问题描述】:

我正在尝试将在线 SOAP Web 服务添加到我在 Visual Studio 中的 Web 应用程序中。我尝试了几个教程,但大多数教程都侧重于在本地主机上创建服务器。

在我的网络应用程序中,我想使用以下网址从网络服务中获取所有国家/地区。 http://www.webservicex.net/country.asmx?op=GetCountries

它提供以下 SOAP 请求和响应。

请求

POST /country.asmx HTTP/1.1
Host: www.webservicex.net
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetCountries xmlns="http://www.webserviceX.NET" />
  </soap12:Body>
</soap12:Envelope>

回应

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetCountriesResponse xmlns="http://www.webserviceX.NET">
      <GetCountriesResult>string</GetCountriesResult>
    </GetCountriesResponse>
  </soap12:Body>
</soap12:Envelope>

我是如何添加网络服务参考的,

在 Visual Studio 中,我在我的项目中单击 -> 添加 -> 服务参考 -> 高级选项卡 -> 添加 Web 参考 -> 输入 Web 服务的 URL(http://www.webservicex.net/country.asmx)。

我的问题是如何从网络服务中获取国家/地区。我尝试了几种方法,但没有成功。 如何从我的 asp 文件中调用服务。

【问题讨论】:

  • 您是否尝试过使用任何其他类型的网络服务..?它必须是肥皂..?你能用 Linq to Sql 网络服务吗..soap 太老了,过时了..WCF web services 更容易
  • 好吧,我的要求说我必须使用 SOAP。
  • 我知道这是你老板想要用 SOAP 编写的东西,因为你通过绕过 SOAP 通过 Web 服务生成有效的 XML 我认为你的问题涉及不正确地使用/实例化 Web 服务和或代理

标签: c# asp.net web-services soap


【解决方案1】:

您实例化已构建的类,然后调用成员函数:

protected void btn_Click(object sender, EventArgs e)
{
    ServiceReference1.countrySoapClient Client = new ServiceReference1.countrySoapClient("countrySoap12");

    String Countries = Client.GetCountries();
}

酷,返回的字符串看起来像从 DataSet 导出的 XML。您应该能够将其读入一个新的 DataSet....然后将其绑定到某个东西。

【讨论】:

    猜你喜欢
    • 2011-10-10
    • 2011-10-04
    • 2011-02-18
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多