Solved

Dynamic WEb Reference URL at Runtime with a Desktop Application

Posted on 2009-07-10
12
485 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
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

803 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