【问题标题】:Call Soap Service From a Windows Service从 Windows 服务调用 Soap 服务
【发布时间】:2014-12-18 21:32:50
【问题描述】:

我正在桌面应用程序中使用 Soap 服务 http://example.com/soap/webservice.php。我创建了一个单独的类库包含该服务并使用这个类库在我的主应用程序中使用它,我工作正常。

这是我正在使用的代码:

MyService.PushServerWSPortTypeClient obj = new MyService.PushServerWSPortTypeClient();

string result = obj.auth(apiId, UserName, Password);

这是完美的工作。

但是当我在我的 Windows 服务中使用此服务时,我遇到了异常:

http://exmaple.com/soap/webservice.php 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关详细信息,请参阅 InnerException(如果存在)。

我知道这个异常意味着它无法在我的服务中找到它的端点,但是在我的类库中,它的 app.config 中提到了端点,我还在我的Windows 服务 app.config 也是如此。

这是 app.config 中的代码:

<system.serviceModel>
      <bindings>
          <basicHttpBinding>
              <binding name="PushServerWSBinding" />
          </basicHttpBinding>
      </bindings>
      <client>
          <endpoint address="http://example.com/soap/webservice.php"
              binding="basicHttpBinding" bindingConfiguration="PushServerWSBinding"
              contract="MyService.PushServerWSPortType" name="PushServerWSPort" />
      </client>
  </system.serviceModel>

内部异常消息:

无法解析远程名称:'api.example.com'

堆栈跟踪:

在 System.Net.HttpWebRequest.GetRequestStream(TransportContext& 上下文) 在 System.Net.HttpWebRequest.GetRequestStream() 在 System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()

【问题讨论】:

  • 你能在运行服务的机器上的浏览器中点击端点吗?从表面上看,windows 服务似乎无法解析 Web 服务端点的域名。
  • @BenRobinson 当我访问 example.com/soap/webservice.php 时,它可以在该机器上的浏览器中运行,但是当我只写这个 example.com 时,它会显示 在此服务器上找不到请求的 URL /。,这是导致问题的原因吗?
  • @BenRobinson 如果您需要,这里是确切的网址:api.clickatell.com/soap/webservice.php

标签: c# soap windows-services


【解决方案1】:

您的浏览器可能使用了一些您的代码没有使用的代理(或使用不同的代理)。

如果是这种情况,请确保在浏览器中设置 WebClient.Proxy 属性以匹配一个,使用 WebProxy 类使用

WebClient webClient = new WebClient()) 
{ 
  webClient.Proxy = new WebProxy("myproxy.com"); 
  result= webClient.DownloadString(someURL);
}

如果不确定,试试他的DNS-Testing 链接。这不太可能,但如果浏览器使用与您的代码不同的 DNS,则有可能。

【讨论】:

  • 顺便说一句我不确定
【解决方案2】:

在挖掘了一整天之后,今天我们就这个奇怪的问题联系了我们的网络部门,我们了解到当我们使用桌面应用程序调用任何 SOAPWCF服务请求通过代理服务器,但在 Windows 服务 的情况下,请求通过 系统网关/防火墙 并且在防火墙端口 80 上阻塞,导致请求无法调用服务器。

当我们为服务特定的 url 打开端口 80 时,它开始正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多