Self Host WCF with Dynamic URL - c#

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

Related

Azure ServiceFabric Stateful Service, not accessible after configuration in portal

Created a Basic Azure Service Fabric , Stateful Service, using reliable service framework using .NET core.
Created a values controller with get operation returning string collection
created endpoint configuration in service manifest with protocol of http
Created DNS service name in the application manifest for the service
Created Azure service fabric Cluster from portal
Configured the nodes with ReverseProxy and Enable DNS
Configured the LB rules 8081,80,19080,19000
Have healthprobe at 19000,19080,8081
Published my azure fabric application from Visual studio, and I can open the fabric explorer, it shows my services are deployed correctly
but not able to access the service from outside of cluster
http://domain.eastus2.cloudapp.azure.com:19080/MyCalculatorApplication/AgeCalculatorService/api/values throws exception as {"Error":{"Code":"E_INVALIDARG","Message":"Invalid argument"}}
When you are trying to use the naming service of service fabric, first you should resolve the endpoint using this url:
http://domain.eastus2.cloudapp.azure.com:19080/Services/MyCalculatorApplication/AgeCalculatorService/$/ResolvePartition?api-version=3.0&PartitionKeyType=1&timeout=60
Then you can use one of the endpoints
I'm not sure that this is the correct endpoint.
Your url should be something like this:
http://domain.eastus2.cloudapp.azure.com:SERVICEPORT/api/values

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.

Get URL of Website from where Web Service Call is Made

In my web service, how can I check the URL of the web site from where the web service call originated please? Thank you.
In your scenario I think you have a web application hosted in IIS and that web application is consuming asmx web services and you need to get the name of the page which called the service in the service implementation.
The ASMX webservices are not limited to access from the web sites. They can be accessed from the desktop applications as well which don't have webpage url. So in this context we expect to get the web page URL as is inside the web service implementation. You may get the IP address of the caller machine. But seems that is not enough.
So only way is to pass the name of the webpage from the calling code via parameter or http header.
I believe what you're asking is for the requesting URL of the Web service called.
webpage.aspx -- (calls ) --> MyWebService.asmx.
the referrer is webpage.aspx
Try using Context.Request.UrlReferrer from the webservice.

How to enable and share Cached Items in WCF?

I have a WCF Service which is hosted in my Web Application. Both are hosted under the same virtual directory. Don't they run under the same Application Domain and share the HttpContext?
I added a new item to my cache from within the WCF service:
HttpContext.Current.Cache["FirstName"] = "Will";
How could I access this value from the web page?
I tried the below after calling the WCF web service but it was null:
HttpContext.Current.Cache["FirstName"]
Thanks,

Bind web services at runtime

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);

Categories