Click here to Skip to main content
15,566,625 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello everyone, this problem has been bugging me since yesterday.
I have written a webservice that basically gets data from a weatherapi provider in the form of xml. I have referenced this webservice in a class library and used the dll of this library in another project that i am working on.
At first, the usercontrol(i've used the methods in a usercontrol in asp.net) worked fine and showed the results...but after few runs, my website generated an exception
as follows:
C#
No connection could be made because the target machine actively refused it 127.0.0.1:5230

Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:5230

Source Error:

Line 81:         [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetWeatherCondition", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 82:         public System.Xml.XmlElement GetWeatherCondition(string strLocation) {
Line 83:             object[] results = this.Invoke("GetWeatherCondition", new object[] {
Line 84:                         strLocation});
Line 85:             return ((System.Xml.XmlElement)(results[0]));


when i use the webreference without the classlibrary in the same solution this works fine. Am i doing something wrong while referencing it in the class library??...And if so why did it work the first few times??


I actually built the webservice in vs2010 and consumed it in an aspx file...it runs perfectly...but one thing i noticed is that...it uses port localhost:5230, now when i use the classlibrary in vs2008 that contains the webservice reference built in vs2010, i'm getting the above exception...the thing that interested me was that the target machine....localhost:5230 was actively refused...the same port vs2010 was using?? is there a way i can change which port the localhost listens to?
Posted
Updated 26-Oct-12 4:33am
v2
Comments
Sergey Alexandrovich Kryukov 25-Oct-12 13:56pm    
I don't think there can be any problem with using the library, ever. It's only possible that in migration to the use of the library you made a subtle change in using code; some assumption that was incorrect in first place but met, was broken... For example (I'm not telling this is the reason, just the example), you explicitly use the assembly name somewhere, or something like that).

If you still cannot resolve it, you probably can create a complete but absolutely minimized solution and reproduce the problem. If you can reproduce it and still won't figure out the problem, at least you will be able to post its code using "Improve question". It should be something simple.
--SA
Minghang 26-Oct-12 9:25am    
Thank you sergey for your information. I forgot to mention but...i developed the webservice in visual studio 2010...when i consume the webservice in aspx file in vs2010
the port it uses is localhost:5230. Then i noticed when running the class library from vs2008 it gives the exception socket error...target machine acitively refused it
localhost:5230??...is it because vs2008 is trying to use the same port as vs2010??...if so how can i solve it?
Sergey Alexandrovich Kryukov 26-Oct-12 12:16pm    
I did not get about "localhost". What host is that? of the Service? If so, did you also change it to the "real" URI?

Anyway, please see my advice in my answer.
--SA
Minghang 26-Oct-12 12:54pm    
Hello sergey thank you very much for you time. I made my webservice as an application in the iis and used the url for the web reference in my class library.
It Finally worked. Thank you again for your time. You should've answered rather than comment. I would've 5 stared you. thanks anyways.
Minghang
Sergey Alexandrovich Kryukov 26-Oct-12 13:30pm    
With pleasure -- it will only improve formatting... :-)

I wasn't sure my advice will lead you to the resolution, because it could be something I did not see without your code.
But I'm very glad you sorted thing out.

If you say it's indeed helpful, please also accept the answer formally (green button) -- thanks.

At this point, let's close the issue.

You are very welcome.
Good luck, call again.
--SA

1 solution

I would advise you to go back to working version and do one step at a time. Let's say, you have two steps: going from local hos to real host, and from monolithic to adding an extra assembly and using it. The second step is poor re-factorization (re-factorization is, by definition, something with is supposed not to modify behavior in any way, so it could be done 100% formally, without thinking of the semantic); and moving some class from one assembly to another is, assuming sufficient access modifiers, in fact, logically equivalent to just renaming source code file or moving some declaration from one file to another — assembly boundaries are very transparent, only internal needs to become public. For example, you do re-factorization only, re-test. If everything is all right, change implementation. Of in the opposite order, but still one step at a time.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900