1

客户向我提供了他们在 .net asmx webservice 的位置。我创建了一个库,我在我的 Web 应用程序中使用它来与他们的 Web 服务进行通信。

在我的库中,我创建了对 asmx 的 Web 引用

这是我调用他们服务的代码

using (vendorproxy.vendorproxy wsProxy = new vendorproxy.vendorproxy())
{
    wsProxy.Credentials = new System.Net.NetworkCredential(uname, pwd);

    using (Stream xmlStream = xmlUtil.GenerateStreamFromString(
        wsProxy.GetData(index)))
    {
        //
    }
}

public Stream GenerateStreamFromString(String inputString)
{
    byte[] bytes = UTF8Encoding.UTF8.GetBytes(inputString);
    MemoryStream strm = new MemoryStream();
    strm.Write(bytes, 0, bytes.Length);
    return strm;
}

客户开发了一个测试应用程序来测试他们的服务并且它可以工作。但是,我的应用程序在他们的系统上部署时失败。我无法单步执行代码,因为客户端没有将服务暴露在他们的网络之外。这是由他们开发的,仅通过 xml 文件和他们的 wsdl 提供示例输出。

异常详情:

at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)     
at System.Net.HttpWebRequest.GetRequestStream()     
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(
   String methodName, Object[] parameters)     

我的类库的 App.config 具有对服务的 Web 引用和执行调用的类库。我的网络应用程序使用了类库

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="clientService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.serviceModel>
        <bindings />
        <client />
    </system.serviceModel>
    <applicationSettings>
        <clientService.Properties.Settings>
            <setting name="clientService_client_client" serializeAs="String">
                <value>http://localhost:2362/client.asmx</value>
            </setting>
        </clientService.Properties.Settings>
    </applicationSettings>
</configuration>

已解决:这在我修改了我的原始代码后有效

using (vendorproxy.vendorproxy wsProxy = new vendorproxy.vendorproxy())
{
    wsProxy.Credentials = new System.Net.NetworkCredential(uname, pwd);
}

using (vendorproxy.vendorproxy wsProxy = new vendorproxy.vendorproxy())
{
    wsProxy.Credentials = new System.Net.NetworkCredential(uname, pwd);
    wsProxy.URL = [correct asmx location read from config file]
    //not sure why it would not automatically pick up from config file. 
}
4

2 回答 2

1

您可能在代理访问外部地址时遇到问题,您可能需要在配置中添加类似的内容。

  <system.net>
    <defaultProxy>
      <proxy
          autoDetect = "true" />
    </defaultProxy>
  </system.net>

问候

于 2011-03-04T13:15:40.573 回答
0

我最好的猜测(基于有限的异常信息):

当您将其部署到他们的服务器上时,您应该更新用于连接到 Web 服务的位置。

该位置通常是 web.config 或 app.config 内的 URI/URL。

于 2011-03-04T12:47:58.247 回答