Solved

Dynamic WEb Reference URL at Runtime with a Desktop Application

Posted on 2009-07-10
12
483 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:Veljean
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:RyanAndres
Comment Utility
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
 
LVL 1

Author Comment

by:Veljean
Comment Utility
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
 
LVL 3

Expert Comment

by:MrHswede
Comment Utility
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
 
LVL 8

Expert Comment

by:RyanAndres
Comment Utility
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
 
LVL 1

Author Comment

by:Veljean
Comment Utility
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
 
LVL 15

Expert Comment

by:jinal
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:Veljean
Comment Utility
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
 
LVL 1

Author Comment

by:Veljean
Comment Utility
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
 
LVL 15

Expert Comment

by:jinal
Comment Utility
Can you put your code snippet ove here ?

I already used this at many place so i can help you .
0
 
LVL 1

Author Comment

by:Veljean
Comment Utility
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
 
LVL 15

Accepted Solution

by:
jinal earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:Veljean
Comment Utility
Thank you jinal!!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

763 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

6 Experts available now in Live!

Get 1:1 Help Now