Method 1: Sometimes you need to dynamically set the WebService address so that it will be regenerated 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";
}
}