Dynamically set web service url

Scenario: I run the code on a client that connects to the server and uses the web service to retrieve the SharePoint list data. I am using the Visual Studio 2010 service link to get the web service for my SP site and get my data from the list. It is working. Now, how can I code it so that when I want to switch from Test to Production, my web service calls will work? Please note that the web service is a SharePoint web service, I am not writing it. I use it only. Is it possible? I have the opportunity to make sure that the site is the same (with the exception of URLS) in both environments (for example, backing up the SP site and creating it). Thanks for any suggestions.

Summary:

Basically I am looking for a better way to go from test to production without recompiling my code that uses the SP web service. Also, as a side note, if anyone knows how similar the sites of the test / production access point are, [so that the web service works with both and changing the URL) .. this would be useful .

Decision

You can use the project configuration file to specify the location of the web service. The .svcdatamap files and other files in the VS project are for development-time use only, and the URL that is actually used to connect to the SharePoint web service is passed as an argument to the System.Data.Services.Client.DataServiceContext object. This is only tangent, but to create your own WCF web service, see Link. BTW, the web service will work without recompiling anywhere in the SharePoint list that has the same list name, and the column you request has the same name.

+6
source share
4 answers

As far as I know, Visual Studio Tools for Office projects allow you to have the app.config file in your project. I expect Visual Studio to create the app.config file and add the necessary configuration options associated with the web service link. In any case, you need to save the correct web service URL - app.config, registry, or even the database.

If you cannot save the web service endpoint address information in the app.config file, you can manually configure the proxy server.

  • If the .asmx link is added as an obsolete "web link" in Visual Studio, then you need to set the proxy object's Url property value before you call any web service methods. For instance:

     MyASMXWebService proxy = new MyASMXWebService(); proxy.Url = "web service url"; proxy.HelloWorld(); 
  • If this is a .svc WCF service link, then the situation becomes a little more complicated. You will need to create the web service endpoint programmatically. For instance:

     BasicHttpBinding binding = new BasicHttpBinding(); EndpointAddress endpoint = new EndpointAddress("web service url"); ChannelFactory<IMyWCFWebService> factory = new ChannelFactory<IMyWCFWebService>(binding, endpoint); IMyWCFWebService proxy = factory.CreateChannel(); proxy.DoWork(); 
+14
source

Because SharePoint Services (SVC) does not provide a proxy server, option 2 will not work. Links to both places should be included in your application, and then use parm to distinguish production from the test. I believe that 2013 is likely to correct this error.

+1
source

You must edit the URL in your web.config project

0
source

An example of a simple SharePoint:

 MyService.ListsSoapClient client = new MyService.ListsSoapClient(); client.Endpoint.Address = "site url"+"/_vti_bin/lists.asmx"; 
0
source

Source: https://habr.com/ru/post/893374/


All Articles