Method 1:Sometimes we need to dynamically set the WebService address so that it will be re-generated when published to different servers. in config, the WebService address is dynamically configured and a lot of information is found online. This method is easy to use and implement. Modify the local proxy class (Add a new class to inherit your WebService proxy class)
NamespaceWeb_service
{
[System. Diagnostics. debuggerstepthrough (), system. componentmodel. designercategory ("Code"),
System. Web. Services. webservicebinding (name = "", namespace = "")]
Public ClassDynwebservice: selfwebservice
{
PublicDynwebservice ():Base()
{
// Set the default WebService address
This. Url ="Http: // localhost/WebService. asmx";
}
PublicDynwebservice (StringWeburl ):Base()
{
This. Url = weburl;
}
}
}
Note: selfwebservice the WebService you referenced
Deploy the Web Service URI to the configuration file.
<Add Key="Webservicekey" Value="Http: // xxxx/WebService. asmx"/>
Final Implementation (call)
Private VoidWebservicetest ()
{
StringWebserviceurl = configurationmanager. appsettings ["Webservicekey"]. Tostring ();
Web_service.dynwebservice DWS =NewWeb_service.dynwebservice (webserviceurl );
StringResult = DWS. helloworld ();
}
Note: helloword () is the WebService method you call. Here we assume it returns a value of the string type!
OK. Now we can fix it!
Method 2:
You can choose the Web Serivce file on your client (like the one in the earth-shaped area). My name is the localhost file, then there is a URL in the right-side health check, and then the dynamic modification will be made to the dynamic modification. Web. config appears
<Add Key="Webpos. localhost. myservice" Value="Http: // localhost/soapservice/myservice. asmx"/>
What I think is that this kind of child may be affected by your web service. This time
Http: // localhost/accesswebpos/web references/localhost/reference. CS
File appears
PublicMyservice ()
{
StringUrlsetting = system. configuration. configurationsettings. deleettings ["Webpos. localhost. myservice"];
If(Urlsetting! =Null))
{
This. Url =String. Concat (urlsetting ,"");
}
Else
{
This. Url ="Http: // localhost/soapservice/myservice. asmx";
}
}
Another method for dynamically calling webserice is to simulate and generate a client proxy class to realize dynamic calling of WS.
Address: http://topic.csdn.net/u/20090220/10/08c8ca6f-3733-40ff-840e-d6ca6894ab35.html