views:

35

answers:

1

I have a ASP.NET (C#) web page which utilizes a VB class library. The VB library performs a SOAP POST to a remote web service and returns a message. However the VB library keeps running into a "No connection could be made because the target machine actively refused it xxx.xxx.xxx.xxx"

However, I've also created a C# test client which consumes the same VB class library and can perform the post just fine!

So what is going on here?

Default.aspx:

protected void Page_Load(object sender, EventArgs e)
    {
        String soapString = ........
        MyVBMiddleTierObject.PostMgr pMgr = new MyVBMiddleTierObject.PostMgr();
        Response.Write(pMgr.DoPOST(soapString));
    }

VB Middle Tier:

Public Function DoPOST(ByVal soapMsg As String) As String
  Dim encode As UTF8Encoding = New UTF8Encoding()
  Dim buff() As Byte = encode.GetBytes(soapMsg)

  Dim client As HttpWebRequest = CType(WebRequest.Create(ConfigurationManager.AppSettings("SoapService")), HttpWebRequest)
  client.Headers.Add("SOAPAction", "")
  client.ContentType = "text/xml;charset=utf-8"
  client.Accept = "text/xml"
  client.Method = "POST"
  client.ContentLength = buff.Length
  client.Timeout = 5000

  Dim s As Stream = client.GetRequestStream()
  s.Write(buff, 0, buff.Length)
  s.Close()

  Dim response As WebResponse = client.GetResponse()
  s = response.GetResponseStream()
  Dim sr As StreamReader = New StreamReader(s)
  sPostResult = sr.ReadToEnd()
  response.Close()

  DoPOST = sPostResult

End Function

C# Test client:

class Program
    {
        static void Main(string[] args)
        {
            String soapString = ........
            MyVBMiddleTierObject.PostMgr pMgr = new MyVBMiddleTierObject.PostMgr();
            String s = pMgr.DoPOST(soapString);
            Console.WriteLine(s);
        }
    }

So why is my C# Test Client working just fine, but my web page not?

Update

Soap Message:

<soapenv:Envelope xmlns:java="java:com.xyz.service"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:vcs="http://schemas.xyz.com/vcs"&gt;
  <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1"
    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
      <wsse:UsernameToken wsu:Id="UsernameToken-5775010" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility- 1.0.xsd">
        <wsse:Username>JoeShmoe</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"&gt;123456789&lt;/wsse:Password&gt;
      </wsse:UsernameToken>
    </wsse:Security>
  </soapenv:Header>
  <soapenv:Body>
    <vcs:theirService>
      <vcs:theirMethod>
        <java:Frequency>M</java:Frequency>
      </vcs:theirMethod>
    </vcs:theirService>
  </soapenv:Body>
</soapenv:Envelope>

Again, the exact same soap string is being posted (by my test client, and by my web page) but only my test client can connect...


Update to include web.config

<configuration>
    <appSettings>
        <add key="SoapService" value="https://www.wxy.com/theirService"/&gt;
    </appSettings>
    <connectionStrings/>
    <system.web>
        <compilation debug="true" strict="false" explicit="true"/>
        <authentication mode="Windows"/>
    </system.web>
</configuration>

It's pretty basic...

+1  A: 

The error means the computer your code connected to does not have a server listening on the port you requested (80 I assume). That could mean that the IP is wrong (it found a computer, but the wrong one), or the port is wrong. We would need to see your soapString, to further diagnose.

try putting this in your web.config to ensure credentials are passed along to your web service.

<identity impersonate="true" />

or if you are not using a windows token, just specify the userid and password.

<identity impersonate="true"
          userName="domain\user" 
          password="password" />

You also need to use a proxy with credentials.

client.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials

or

client.Proxy.Credentials = New Net.NetworkCredential("UserName", "Password")
Carter
But i send the same soap string. The C# client and the ASP.NET web page send the same soap string. But the C# client can actually POST it, while the ASP.NET client gets the error.
Dave
It is possible that the problem is related to authentication, since the ASP.NET page must impersonate the client in order to make a second request to the web service. Can you post your web.config authentication info?
Carter
That thought crossed my mind too, but it shouldn't matter who performs the POST, the logged in user or the ASPNET account.
Dave
Try putting "<identity impersonate="true" />" in your web.config. This should eliminate security as an issue.
Carter
EDIT: You also should try using a proxy. (I'm looking through some old code to find an example).
Carter
I did just try, i also tried it by setting the username and password attributes too, but still not working.
Dave
Try setting the "proxy" credentials as outlined above.
Carter
That solved it, thanks! Of course my test client was being run under MY credentials, but the web page was running as NetworkService or ASPNET and was being blocked at the proxy.
Dave
You are welcome. Glad I could help.
Carter