Unable to connect to remote server using SoapHttpClientProtocol

21.4k views Asked by At

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

There are 2 answers

7
Tony Abrams On

My best guess (based off the limited exception information):

You should be updating the location used to connect to the webservice when you deploy it on their server(s).

The location is usually a URI/URL inside of the web.config or app.config.

1
Iain On

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