Bind web services at runtime - c#

I have some knowledge about web services and how to add web preferences in the project.
In my project there is a same web services will run on more than two server.
All web services are same just their servers are different.
So is there a way to add web services dynamically? and i can call web services from the server which user specify if there is no web services available then it will return false.
I need to call server dynamically as user specify server name.

Use web service proxy's Url property to set the new url dynamically. Store URL of the web service in your application's parameter table / config file. At runtime always get the web service's Url from that parameter and set it to your web service's Url as destination.
Ok, I'll give an example how to use it. For example let's say we have to add this web service to your project :
http://server1/service1/service.asmx
And then we specify MyService as proxy name to your web service. Then while we use this web service set the Url property like that to specify your proxy's destination :
MyService myService = new MyService();
myService.Url = "http://server2/service1/service.asmx";
myService.GetOrders(customerNo);

Related

Self Host WCF with Dynamic URL

I am new to WCF, I am trying to create a WCF selfhost service with dynamic URL, which will be used to authentication user from client computer. this service will be installed in all client computers and web application should work if it finds this WCF service in client computer. Please Help.
First, you can implement self-hosted wcf,
https://www.c-sharpcorner.com/UploadFile/137605/self-hosting-in-wcf/
https://learn.microsoft.com/en-us/dotnet/framework/wcf/samples/self-host
and then dynamically switch the wcf web service reference url path through the configuration file.
How to make your Service-Reference proxy URL dynamic?
Dynamically switch WCF Web Service Reference URL path through config file
How Dynamically change URL in a WCF Custom Behavior

Calling an asmx service from Web API

Need to call asmx service from one of my get methods in web api .How can we do that ? Can we add a config entry in appsettings to the asmx service url and call it from the web api get mehod?
web config app settings entry:
key="myOldWebservice" value = "http://testAPI/webservice/client.asmx"/>
Add the asmx service as a Service Reference to your project in VS and call asmx methods from that reference. Just like invoking methods in dlls.

How to consume a soap service url through a c# winform app

I have soap service url. I added that url as Add web reference and access its properties and methods but the problem is I want to access the properties and method exposed by service by adding that service in app.config. I dont want to add service reference by right click and add service reference.

How to call asmx web service in .NET?

I have to develop a component in .NET to call asmx service(which has user name and password) to send sms. How can i call web service ?
You have to add web reference into your application. Also add a key config for the webservice url and call the same in reference.cs of web proxy class. It will be helpful whenever url of webservice gets change.
Simply add a service reference of the asmx web service you want to call to your project and create an object out of the service and call the method.

how change default display of WCF service

I have deployed a WCF service. When that service is accessed from web browsers it is showing a message :
You have created a service.
To test this service, you will need to create a client and use it to
call the service. You can do this using the svcutil.exe tool from the
command line with the following syntax:
svcutil.exe http://sitename/Service1.svc?wsdl
You can also access the service description as a single file:
http://sitename/Service1.svc?singleWsdl
This will generate a configuration file and a code file that contains
the client class. Add the two files to your client application and use
the generated client class to call the Service.
How to change this default message shown by WCF service ?
You can't override the default page. But you can use a Help Page. Also you could create a totally separate page to describe your service.

Categories