简体   繁体   中英

config web service from code behind

I am creating a windows mobile 6 application which will consume a web service (.asmx) for different clients. As I know, I will need to manually “Add Web Reference”; then I will be able to call those functions. Is it possible to configure web reference as a variable from code behind? That way I can keep the url of web service in a text file. For different client, I just need to edit that text file instead of recompile that application again.

You'll have to add the Web Reference at design time.

At runtime, you can modify the URL of your target web service using the Url property. Here's an example of pulling the target URL from the app.config:

var ws = new MyWebService();
ws.Url = ConfigurationManager.AppSettings["SomeUrl"].ToString();

The only catch here is that the WSDLs of the design-time and run-time services must match.

Yes, just add something like :

<configuration>
    <appSettings>
        <add key="WebReference" value="URLofASMX"/>
...

then call it by :

string URL = ConfigurationManager.AppSettings["WebReference"].ToString();

You'll need to possibly add a new reference to System.Configuration to the project if you can't access ConfigurationManager just by including System.Configuration .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM