How to get the WebService address dynamically from the txt file in Windows Forms - c#

I'm building a small application and I'm using WebService in it. I was using a local WebService just by adding its reference in my project's solution manager.
My question is: is it possible to get the WebService url address dynamically, for example from a .txt file?
Thanks for every help.
Edit:
I want to change the WebService url address in my app's code. After that, the url will be placed in a .txt file and the app will get it from there.

You can set any url for your WebService client using the clients constructor. There you can provide the url to use:
var client = new YourServiceClient("<bindingName>", new EndpointAddress("<your url>"));

Please check solution here. They are accessing the URL from config file, instead of text while.

Related

calling the service URL

I am trying to call a credit card WSDL soap service in my ASP.net web forms. I tried to add the reference of the service in my application. I got the error "Page cannot be displayed. I asked the vendor and he told me that I am using older version of .net and I should use below line of code to fix the issue
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Where should I put the above line in my code and by putting the above, will I be able to call the service. Below is the screenshot of the error message when I am trying to call the service.
There are 2 ways to add a web reference on a project in visual studio.
Using an Url. In this case you can try typing the url on any browser and adding ?wsld at the end of the url, it should to show you the contract just there (like and xml). If it works then you can use THAT url (including the ?wsdl part) as the reference.
From a local file. In this case you can download the wsdl file from the browser (changing the extension to .wsdl when you download it) using the same way as I explained before but when the browser shows you the xml then you download it with the right click. Then in the web reference URL you can reference to the local path of the file.

Windows Service Config not updating

I've got a windows service coded in c#, with a config file:
ProcessingService.exe
ProcessingService.exe.config
Its got a webservice endpoint address in it. This initially went in with the wrong address, so I stopped the service, changed the config file and restarted, but the service is still hitting the original URL.
I then restarted the entire server and still the wrong URL is being accessed.
We have a load of corporate rules about new install versions meaning my turnaround time for compiling a new service and getting it installed will be measured in weeks, leaving the URL broken for that entire time. Is there a way to force the config to update?
(Yes, I've triple checked that the config file is now correct!)
In response to the request for the service setup code, I simply do (class names changed):
WebserviceNamespace.ServiceClass client = new WebserviceNamespace.ServiceClass();
The service config shows the original URL, and I'm using a transformed app.config process to overwrite the new URL in the new config file (again, I've triple checked this). I am generating the service classes as internal though, could this be something to do with it?
OK, so I've now tried installing the service on another computer, stopping it, changing the URL in the config to "nevergonnahappen" and restarted. Requests to that now fail on an invalid url. So it must be something to do with our live server specifically...
make sure that your services is pulling the url from config file.
make sure the services is not cached the url somewhere else after getting it(maybe in memory or file or database).
make sure you pointed to correct folder for the config file, perhaps do a wild search with agent ransack, any other place that is still writing broken url and your services in fact is pointing into it.

Update Web Service Url when clicked button

I have a web service on my c# application. I want to update webservice url when i clicked button. How can i do this.
The web service endpoint address is usually defined in the application's config file, but you can also specify the url in the client's constructor:
MyClient client = new MyClient("http://95.9.5.151/SabisOdemeWS/Service1.asmx");
To make the URL in the Reference.cs map class code behind look for the web service URL in your web.config file, we need to change this setting to Dynamic. See the article here.

how to set webservice url properly?

I have a ASP.NET application. Inside the asp.net application I have a folder called WebServices where I keep all the .asmx files.
I am referring these asmx files inside asp.net .cs files. Instead of giving the full url to the webservice.url property how can i set the path like this.
ds.Url = this.ResolveUrl("~/WebServices/xxx.asmx");
Is HttpServerUtility.MapPath what you're looking for?
ds.Url = Server.MapPath("~/WebServices/xxx.asmx");
You can get hold of it either via Server property in Page class, or via HttpContext.Current.Server chain.
Even better, I'd store this URL in an application configuration file.
Your questions suggests that you have your webservices in the same project as the consuming apllication. This will not work. Move all your webservices into a seperate project.
If your services and cs files both are in same project then you donot need to set the URL as such. These services can be called as if you can call other classes in your application.

Connect to Unknown SOAP Web Service

I would like to build an app in C# that connects to an Apache AXIS web service and performs the following operations via SOAP.
Login in to the server.
POST string data to server
Receive and display server response
Here's the tough part. I do not have access to the server, nor do I know where the .JWS file is located on the server. I was able to get to the WSDL file in my web browser, so I know a "Login" operation exists as well as an operation to take in data.
I have tried accessing the web service via URL, but I keep getting this message:
Hi there, this is an AXIS service!
Perhaps there will be a form for
invoking the service here...
In summary, is there anyway I can connect to this web service when all I have is the URL of the WSDL file? Are web services accessible via URL?
Thank you
Use WCF, and generate client proxies to the web service using the svcutil.exe tool.
running svcutil.exe http://url.to/webservice?WSDL the_wsdl.wsdl /language:C# should generate proxy classes you can use in your C# project, and you'd call the service e.g. like
BasicHttpBinding myBinding = new BasicHttpBinding(); //might not even need these
// 2 lines if you ran svcutil.exe directly on the web service URL
EndpointAddress myEndpoint = new EndpointAddress("http://url.to/webservice");
TestClient client = new TestClient(myBinding,myEndpoint); //the generated classes
// svcutil.exe created
client.SomeOperation(42); // call an SomeOperation of the web service
Thanks for everyone's help. Looking back on this question, I can see how severely confused I was. Here is the solution I followed.
Assuming you know the URL of the WSDL file of the service you wish to connect to then just do the following.
Boot up Visual Studio
On the top toolbar navigate to Data -> Add New Data Source then choose Service in the new dialog
In the address bar, enter the URL of the wsdl file (EXAMPLE: http://server.com/services/displayName?wsdl)
Near the bottom of the dialog, change the namespace to something relevant to the project (EXAMPLE: sampleService)
Now Visual Studio should compile the client proxies for you that you can use to access the web services on your server. To access one of the services, all you need to do is create a new object from the class.
//Example
sampleService.ClassName test = new sampleService.ClassName();
test.displayName("Jack");
See http://msdn.microsoft.com/en-us/library/bb552364.aspx for a starting point

Categories