Dynamic WEb Reference URL at Runtime with a Desktop Application

Im accessing a Web Reference in my desktop application.  I want to edit the Web Reference URL under certain circumstances , but i don't know how... i have investigated in internet but only I found examples with Web Appications ,  there are mentions that the key is the file Web.Config, but in desktop i dont have that file... how i can do this?
LVL 1
VeljeanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RyanAndresCommented:
Note sure if you can do that during runtime. The endpoint should be in the app.config or your AssemblyName.config (when compiled).

Changing the web reference url is directly associated with its Service References files location in the Service References directory (ie. wsdl, disco, datasources, and the other xsd files).

What are you really trying to do?
0
VeljeanAuthor Commented:
Hi Ryan

I need to switch during Runtime the Web Reference URLs

http://maptp12.map24.com/map24/webservices1.5
http://maptp17.map24.com/map24/webservices1.5
http://maptp27.map24.com/map24/webservices1.5

these are the 3 possible values.

Only changing the URL value from the app.config xml file  can fix my problem?
0
MrHswedeCommented:
Not 100% sure if this is what you are looking for.
Here is two links to a microsoft web-page
http://msdn.microsoft.com/en-us/library/aa984386(VS.71).aspx
http://msdn.microsoft.com/en-us/library/d9w023sx.aspx 
 
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

RyanAndresCommented:
Veljean,

I would add all web service endpoints as references and put logic in your that would select which one to use. Keep in mind each reference will not have the same base type so you may have to use a proxy to seamlessly control all of them.
0
VeljeanAuthor Commented:
mmmm sounds good... i dont have many experience in this but I like the idea, I think all the references are the same basically I switched URL because each one si a different continent (Asia, America, etc) and im developing a geocoder. Where i can get information in order to do  this? Thank you for you help!!
0
jinalCommented:
For example your webservice proxy class name TestWebSerivce.Service1

Try this way.

TestWebService.Service1.Url =  ""  ;  // your url;

If you not found Url property over here then please add System.Web.Services assembly refrence.
0
VeljeanAuthor Commented:
Hi jinal:

Hi try your solution but without result... i dont know if im getting the correct assembly or class name... can you help me to get it?  
0
VeljeanAuthor Commented:
RyanAndres... I try your solution too, but is not practical since I use a lot of different objects and code made by the Web Service,  put logic and select the appropriated Reference makes my code long and not practical... could be my last option but if i have a better one I would like to do it... any other ideas ?  :(
0
jinalCommented:
Can you put your code snippet ove here ?

I already used this at many place so i can help you .
0
VeljeanAuthor Commented:
This is one part (I think the most representative), as you can se I use a lot of objects from the WEb Reference " Map24Geocoder51" , i can edit the url of  objMap24Geocoder5 like

objMap24Geocoder5.Url = "http://maptp17.map24.com/map24/webservices1.5?soap=Map24Geocoder51&service_version=20070724";

But the rest of the objects (RH
,objSEarchFreeRequest , etc) don't have this property (url) , so they are referenced to the first web reference with the default url.

Let me know if you have more questions...

Map24Geocoder51.Map24Geocoder51 objMap24Geocoder5 = new Map24Geocoder51.Map24Geocoder51();
 
Map24Geocoder51.RequestHeader RH = new Map24Geocoder51.RequestHeader();
RH.Map24ID ="codeID";
 
Map24Geocoder51.MapSearchFreeRequest objSEarchFreeRequest = new Map24Geocoder51.MapSearchFreeRequest();
 
Map24Geocoder51.MProperty objMProperty = new Map24Geocoder51.MProperty();
objMProperty.Key = "Type";
objMProperty.Value = "7";
 
 
Map24Geocoder51.MProperty[] objMPropertyArray = new Map24Geocoder51.MProperty[]
            {
                objMProperty
            };
                       
string[] arrAdress =  new string[dtTableG.Rows.Count];
            
objSEarchFreeRequest.MaxNoOfAlternatives = 1;
objSEarchFreeRequest.Properties = objMPropertyArray;
 
Map24Geocoder51.MapSearchResponse Response = objMap24Geocoder5.searchFree(RH, objSEarchFreeRequest);
 
for (int r = 0; r < dtTableG.Rows.Count; r++)
{
 
  if (dtTableG.Rows[r].ItemArray[0].ToString() != " ")
   {
                    arrAdress[r] = dtTableG.Rows[r].ItemArray[0].ToString() + " " + dtTableG.Rows[r].ItemArray[1].ToString() + " " + dtTableG.Rows[r].ItemArray[2].ToString() + " " + dtTableG.Rows[r].ItemArray[3].ToString() + " " + dtTableG.Rows[r].ItemArray[4].ToString() + " " + dtTableG.Rows[r].ItemArray[5].ToString();
 
objSEarchFreeRequest.SearchText= arrAdress[r];
                                
MakeParenTable(Response,table);
                   
                }
 
            }
            
            clsSaveData.ExportExcel(table, "c:\\ResultGeo.xml");
        }

Open in new window

0
jinalCommented:
You jsut have to set for this objMap24Geocoder5 .

But each time when you create object you have to set that it works.

Map24Geocoder51.Map24Geocoder51 objMap24Geocoder5 = new Map24Geocoder51.Map24Geocoder51();
objMap24Geocoder5.Url = "set your dynamic url over here"; 
Map24Geocoder51.RequestHeader RH = new Map24Geocoder51.RequestHeader();
RH.Map24ID ="codeID";
 
Map24Geocoder51.MapSearchFreeRequest objSEarchFreeRequest = new Map24Geocoder51.MapSearchFreeRequest();
 
Map24Geocoder51.MProperty objMProperty = new Map24Geocoder51.MProperty();
objMProperty.Key = "Type";
objMProperty.Value = "7";
 
 
Map24Geocoder51.MProperty[] objMPropertyArray = new Map24Geocoder51.MProperty[]
            {
                objMProperty
            };
                       
string[] arrAdress =  new string[dtTableG.Rows.Count];
            
objSEarchFreeRequest.MaxNoOfAlternatives = 1;
objSEarchFreeRequest.Properties = objMPropertyArray;
 
Map24Geocoder51.MapSearchResponse Response = objMap24Geocoder5.searchFree(RH, objSEarchFreeRequest);
 
for (int r = 0; r < dtTableG.Rows.Count; r++)
{
 
  if (dtTableG.Rows[r].ItemArray[0].ToString() != " ")
   {
                    arrAdress[r] = dtTableG.Rows[r].ItemArray[0].ToString() + " " + dtTableG.Rows[r].ItemArray[1].ToString() + " " + dtTableG.Rows[r].ItemArray[2].ToString() + " " + dtTableG.Rows[r].ItemArray[3].ToString() + " " + dtTableG.Rows[r].ItemArray[4].ToString() + " " + dtTableG.Rows[r].ItemArray[5].ToString();
 
objSEarchFreeRequest.SearchText= arrAdress[r];
                                
MakeParenTable(Response,table);
                   
                }
 
            }
            
            clsSaveData.ExportExcel(table, "c:\\ResultGeo.xml");
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VeljeanAuthor Commented:
Thank you jinal!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.