Solved

Web service call works in Dev but not in Production?

Posted on 2011-03-09
15
2,054 Views
Last Modified: 2012-05-11
I have a section of code I am running which makes a call to a few methods made available through a web service.

The code runs fine in my local machine dev environment.

Then I push the same code up to our test web server and it will not run.  I get the following:


method where exception was raised:  Process_Click -- Campus_Webstore.com.elementexpress.testtransaction.Express (0) - Campus_Webstore.com.elementexpress.testtransaction.Application (1) - Campus_Webstore.com.elementexpress.testtransaction.Credentials (2) - Campus_Webstore.com.elementexpress.testtransaction.Card (3) - Campus_Webstore.com.elementexpress.testtransaction.Terminal (4) - Campus_Webstore.com.elementexpress.testtransaction.Transaction (5) - Campus_Webstore.com.elementexpress.testtransaction.Response (6) - Campus_Webstore.com.elementexpress.testtransaction.TransactionSetupMethod (7) - Campus_Webstore.com.elementexpress.testtransaction.TransactionSetup (8) - Campus_Webstore.com.elementexpress.testtransaction.PaymentAccount (9) - System.Exception (10) - System.Exception (11) -  -- 

MESSAGE:  Unable to connect to the remote server

STACK TRACE:     at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at Campus_Webstore.com.elementexpress.testtransaction.Express.TransactionSetup(Credentials credentials, Application application, Terminal terminal, Transaction transaction, TransactionSetup transactionSetup1, Address address, PaymentAccount paymentAccount, ExtendedParameters[] extendedParameters)
   at Campus_Webstore.WebForm4.Process_Click(Object sender, EventArgs e)

HELP LINK:  

SOURCE:  System

TARGET SITE NAME:  GetRequestStream

INNER EXCEPTION MESSAGE:  A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.120.157.10:80

INNER EXCEPTION STACK TRACE:     at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)

INNER EXCEPTION HELP LINK:  

INNER EXCEPTION TARGET SITE NAME:  DoConnect

ENTIRE EXCEPTION TO STRING:  System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.120.157.10:80
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at Campus_Webstore.com.elementexpress.testtransaction.Express.TransactionSetup(Credentials credentials, Application application, Terminal terminal, Transaction transaction, TransactionSetup transactionSetup1, Address address, PaymentAccount paymentAccount, ExtendedParameters[] extendedParameters)
   at Campus_Webstore.WebForm4.Process_Click(Object sender, EventArgs e)

Open in new window




I just need some help on the troubleshooting.


Remember, this code works in Dev.
0
Comment
Question by:knowlton
  • 9
  • 3
  • 3
15 Comments
 
LVL 18

Accepted Solution

by:
Gary Davis earned 250 total points
ID: 35087942
Basically, the error is a failure in the Connect to the endpoint (Url). If this is the client attempting to call the web service, the remote web service's Url may be incorrectly set (look at the Url property of the web service, it may still be set to the dev machine).

If the problem is the web service itself calling another web service, a similar case exists.

You can set the web service's Url property in code or in the definition of the web reference. The Url may be set as dynamic or static. If dynamic, it will be set in the config file.

Gary Davis
0
 
LVL 5

Author Comment

by:knowlton
ID: 35088751
If I connected to the webservice on my Dev machine, then pushed the code to the testing web server, is there anything I am supposed to do so the webservice will work in testing as well?
0
 
LVL 23

Assisted Solution

by:adilkhan
adilkhan earned 250 total points
ID: 35088806
what I do is... i use wsdl.exe utility within Visual Studio tools and create myself an proxy class. then you can simply put this proxy class into your project and then use it by its local reference (instead of relying on a remote end point reference in your project).

Google wsdl.exe for samples.
0
 
LVL 5

Author Comment

by:knowlton
ID: 35089010
Just to be clear...I am not writing web services I am consuming 3rd party web services.

So the URL to the web service is the same whether I am in dev or testing.  That's the rub.... they web service call works fine in dev but pukes in the testing environment.
0
 
LVL 5

Author Comment

by:knowlton
ID: 35089024
Here is my code that calls the webservice.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Campus_Webstore;
using Campus_Webstore.com;
using Campus_Webstore.com.elementexpress.testtransaction;


namespace Campus_Webstore
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {




            //sample data
            //http://www.localhost.com/WebForm4.aspx
            //?HostedPaymentStatus=Complete
            //&TransactionSetupID=D3BB1DC4-61E5-4916-9CD1-A89891F00637
            //&ServicesID=2784138
            //&ExpressResponseCode=0
            //&ExpressResponseMessage=PaymentAccount+created
            //&PaymentAccountID=3B461203-E1DC-4E6F-A45A-116DA47F10A6
            //&LastFour=6781
            //&ValidationCode=C4B4B89DFFDB4994
        }

        protected void Process_Click(object sender, EventArgs e)
        {
            GlobalMethods.SendEmailMessage("beginning of process click", "begin", false, "");

            Express express = new Express();
            Application application = new Application();
            Credentials credentials = new Credentials();
            Card card = new Card();
            Terminal terminal = new Terminal();
            Transaction transaction = new Transaction();
            Response response = new Response();

            //Setup the Application, Credential, Terminal
            //Transaction, and Card objects
            application.ApplicationID = "930";
            application.ApplicationName = "TCS";
            application.ApplicationVersion = "1";
            credentials.AccountID = "1000842";
            credentials.AccountToken = "397D5620BED0DF8276879058FD0B1438220032C6069392BDA278EE08D3B0D20D6ACC7C01";
            credentials.AcceptorID = "3928907";
            terminal.TerminalID = "01";
            terminal.CardholderPresentCode = CardholderPresentCode.Present;
            terminal.CardInputCode = CardInputCode.ManualKeyedMagstripeFailure;
            terminal.TerminalCapabilityCode = TerminalCapabilityCode.MagstripeReader;
            terminal.TerminalEnvironmentCode = TerminalEnvironmentCode.LocalAttended;
            terminal.CardPresentCode = CardPresentCode.Present;
            terminal.MotoECICode = MotoECICode.NotUsed;
            transaction.MarketCode = MarketCode.Retail;
            transaction.TransactionAmount = "6.54";
            //card.CardNumber = "5499990123456781";
            //card.CardNumber = "5499990123456718";
            //card.ExpirationMonth = "09";
            //card.ExpirationYear = "08";

            //Output returned values to the Response object
            //response = express.CreditCardSale(credentials, application, terminal, card, transaction, 
            //null, null);
            TransactionSetupMethod tsm = new TransactionSetupMethod();

            TransactionSetup ts = new TransactionSetup();

            ts.ReturnURL = "http://www." + HttpUtility.UrlEncode(Request.ServerVariables["SERVER_NAME"]) + ".com/WebForm4.aspx";
            ts.TransactionSetupMethod = TransactionSetupMethod.PaymentAccountCreate;
            ts.Embedded = BooleanType.True;

            PaymentAccount pa = new PaymentAccount();

            pa.PaymentAccountReferenceNumber = "1000842";


            tsm = TransactionSetupMethod.PaymentAccountCreate;

        

            try
            {
                GlobalMethods.SendEmailMessage("before call to trans setup", "", false, "");
                response = express.TransactionSetup(credentials, application, terminal, transaction, ts, null, pa, null);
                GlobalMethods.SendEmailMessage("after call to trans setup", "", false, "");
            }
            catch (Exception eeex)
            {
                GlobalMethods.SendEmailMessage("ERROR in trans setup call", GlobalMethods.GetDetailedExceptionInfo(eeex), false, "");
            }

            
            GlobalMethods.SendEmailMessage("express trans", "ExpressMessage=" + response.ExpressResponseMessage + "\n HostMessage=" + response.HostResponseMessage, false, "");


            GlobalMethods.SendEmailMessage("express trans id", response.Transaction.TransactionID, false, "");

            try
            {
                GlobalMethods.SendEmailMessage("before call to trans setup", "", false, "");
                Response.Redirect("https://testtransaction.hostedpayments.com/?TransactionSetupID=" + response.TransactionSetup.TransactionSetupID); 
                GlobalMethods.SendEmailMessage("after call to trans setup", "", false, "");
            }
            catch (Exception eee)
            {
                GlobalMethods.SendEmailMessage("ERROR", eee.Message.ToString(), false, "");
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect(TextBox8.Text); 
        }
    
    }
}

Open in new window

0
 
LVL 23

Expert Comment

by:adilkhan
ID: 35089075
Right, but did you add any reference to your website? reference of your webservice? if you did then probably this is the issue its working on dev bu tnot local.

my solution above was to replace adding "web reference" and indtead create a proxy class:
http://www.techrepublic.com/article/consume-a-web-service-in-a-net-app/5768122
0
 
LVL 5

Author Comment

by:knowlton
ID: 35089249
I will do my best to follow your suggestions, but a few concerns:

1)  The article is 6 years old  (I'm using VS 2010).
2)  This is a lot of hassle for a web service to function in both dev and testing.

I am still not sure why a Web Reference (which is what I did) is not sufficient.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Author Comment

by:knowlton
ID: 35089255
I am leaving work, but I'll be back on again in about 16 hours.
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 35089476
If you added a web reference to your project, that should be sufficient.

Your code then instantiates the web service then calls the web service passing whatever parameters it needs and you get the results.

  response = express.TransactionSetup(credentials, ...);

So the question is why the test server unable to connect to the url. If you can remote-desktop to your server and then run a browser with the url of the wsdl, you may see (blocked, firewalled, credential issues, etc). If it is a DotNet web service, you can try going to the asmx and possibly use the proxy to test it.

The error you are trying to solve is Unable to connect to the remote server so this looks like DNS. If you were able to connect, you'd get an HTTP error (400, 404, 500, etc).

Gary


0
 
LVL 23

Expert Comment

by:adilkhan
ID: 35092554
I know, i remember having the same issue with adding web reference, its just the way I do my project now, i just find it easier to create a proxy class(myClass.vb), add it into app_code folder and then simply take it from there. if you know how to get to the wsdl file of your web service you should be golden.

Article above it pretty old, here is how to do it with VS 2005, but the concept it prettyy much same.
http://jlab.calumet.purdue.edu/theGateway/v2/0/doc/Instructions/ProxyClassInstructionsVS2005.htm
0
 
LVL 5

Author Comment

by:knowlton
ID: 35098933
https://testtransaction.elementexpress.com/express.asmx

works in my dev machine browser.



does NOT work from the testing webserver.
0
 
LVL 5

Author Comment

by:knowlton
ID: 35100803
I still do not understand why it does not work on the testing webserver.
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 35101972
Can you go to the same asmx url on your testing webserver? Remote-desktop to it if possible. If not, write a little webpage that does an http request to that url and check its response (you should receive the same thing you see when you enter the url on your browser.

If it fails, is it because you can't resolve the DNS name (testtransactionelementexpress.com)? There seems to be a blockage somewhere.

Gary
0
 
LVL 5

Assisted Solution

by:knowlton
knowlton earned 0 total points
ID: 35101986
How can I hunt down WHERE / WHY it is being blocked?

Where / how is this sort of thing allowed / disallowed?
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 35439116
thx
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now