Solved

Dynamic WEb Reference URL at Runtime with a Desktop Application

Posted on 2009-07-10
12
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24827802
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
ID: 24827831
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
ID: 24827841
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 8

Expert Comment

by:RyanAndres
ID: 24827940
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
ID: 24828047
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
ID: 24828720
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
 
LVL 1

Author Comment

by:Veljean
ID: 24859751
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
ID: 24859838
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
ID: 24859940
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
ID: 24860053
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
ID: 24860131
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
ID: 24860567
Thank you jinal!!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

749 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