2
I am developing an application that should connect to several Web services according to the user’s location.
For example:
If the user is in the city "To" it will connect to the web service:
192.168.1.1:8010
if he goes to town "B", will connect to192.168.1.1:8020
, in the city "C"192.168.1.1:8030
, and so on.The address is always the same, what changes is the door.
Simple thing right?! Yeah, but I can’t make it work at runtime at all!
When I change the parameter
URL
of the web service at runtime the server only returnsnull
, back to the original value the communication is restored. The same thing if the change is made before the compilation, ie, compile for city "To", works in the city "To", town hall "B", works in the city "B".
The application is being developed originally for Windows CE using VS2008 and CF3.5, however even in VS2013 with . Net Framework 4.0 the "problem" repeats.
Someone’s been through it?
I created a new application just to test the server exchange, follow the code:
WebReference.WSR testeWS = new WebReference.WSR();
private void btn_Troca_URL_Click(object sender, EventArgs e)
{
if (URL_01)
{
testeWS.Url = "http://192.168.1.1:8010/WSR.apw";
URL_01 = false;
}
else
{
testeWS.Url = "http://192.168.1.1:8020/WSR.apw";
URL_01 = true;
}
}
In this case the original (compiled) URL is "http://192.168.1.1:8010/WSR.apw"
and for that URL everything works normally, when I click the button and switch to the URL "http://192.168.1.1:8020/WSR.apw"
, I only have null as an answer. By clicking again and returning to the original URL, everything works again.
If code is compiled to the URL "http://192.168.1.1:8020/WSR.apw"
the "problem" is reversed.
Remembering that the "URL Behavior" property is set as Dynamic.
Put the snippet of code that connects to the web service currently on top of it to suggest how to do.
– Rafael Leonhardt
Code included above.
– baltazar
I know it’s not one of the best practices, but you’ve thought about referencing all the web services and instantiating and using the right just?
– Marciano.Andrade
In the webservice properties, one of the properties there should be like Dynamic... Take a look there! Select the WS reference and press F4
– Tiago César Oliveira
We gave up making this business work this way and unified the webservices, passing the cities as a parameter. It’s not best practice, but at least we can achieve the goal.
– baltazar