Unable to connect to remote server using SoapHttpClientProtocol

user644702 picture user644702 · Mar 4, 2011 · Viewed 20.1k times · Source

The client has provided me with their location to .net asmx webservice. I created a library which I use in my web application to communicate with their web service.

In my library, I created a web reference to the asmx

This is my code to invoke their service

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;
}

The client developed a test app to test their service and it works. However my application when deployed on their system fails. I cannot step through the code as the client has not exposed the service outside of their network. This was developed by them providing sample output via xml file and their wsdl only.

The exception details:

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 of my class library that has the web ref to the service and one that does the invoking. The class library is used by my web app

<?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>

Solved: This worked after i modified my original code from

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

TO

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. 
}

Answer

Iain picture Iain · Mar 4, 2011

You may be having problems with your proxy getting to an external address you may need to add something like this to your config.

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

Regards