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.
Related
I'm currently in the process of converting project frontend from .netcore web application (razor page) to reactjs, one of the road block we encounter is the dynamic url path that we applied in razor page.
As the application is deployed on IIS under default website, so the url is construct as https://localhost/Project. One of the project requirement is it can to be replicate and deploy many time, so there will be https://localhost/Project{n}. That mean the url path name need to be configurable so the frontend JavaScript will request to the correct api url. What i done was config the pathname in iis application's webconfig and inject it into the razor page, so javascript can refer to the injected pathname variable.
But when come to reactjs, it is a seperate project from backend but they share the same url, and reactjs has no way to get the configurable pathname so it can only stick to whatever set in the public_url/homepage, and it can only be set before project is build. As it is not set dynamically, the frontend point to the right default page but wrong javascript url, so it cant even run the react main chunk js.
Any lead for me to continue on? Or i need to change the way of configurable pathname?
In React you can use standard JS. So in order to get the current path name from your React application, you can do something like:
const pathname = location.pathname
If you need the pathname in many different places in your React project, you can set it as a context. (See this documentation)
Alternatively, if you only need it on the initial load, you can just do a useEffect in your app.js file like:
const {pathname, setPathname} = React.useState();
React.useEffect(()=>{
setPathname(location.pathname);
}, [])
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.
I have a directory which hosts my web services based on ServiceStack. Inside the directory I have a help folder which has some html pages in it. However when I try browse to those pages, ServiceStack thinks that I am trying to hit a route and gives me "Handler for Request not found".
Is there any way to tell ServiceStack to ignore certain routes? If a route matches a directory present in IIS surely it can't be a service route?
http://www.example.com/exampleservice/metadata <-- fine
http://www.example.com/exampleservice/help/main.html <-- has nothing to do with ServiceStack as it's a directory
This looks to have been nicely implemented in ServiceStack v4. Demis posted about it here.
The Virtual FileSystem is now fully integrated into the rest of ServiceStack, this enables a few interesting things:
The Config.WebHostPhysicalPath sets where you want physical files in ServiceStack to be serve from
You can now access static files when ServiceStack is mounted at a custom path, e.g. /api/default.html will serve the static file at ~/default.html
By Default, ServiceStack falls back (i.e when no physical file exists) to looking for Embedded Resource Files inside dlls.
You can specify the number and precedence of which Assemblies it looks at with Config.EmbeddedResourceSources which by default looks at:
The assembly that contains your AppHost
ServiceStack.dll
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.
Okay, simple situation: I'm writing a simple console application which connects to a SOAP web service. I've imported a SOAP Service reference and as a result, my application has a default endpoint build into it's app.config file.
The web service, however, can run on multiple servers and the URL to the proper web service is passed through the commandline parameters of my application. I can read the URL, but how do I connect the web service to this custom URL?
(It should be very simple, in my opinion. It's something I'm overlooking.)
Is this using an auto-generated class deriving from SoapHttpClientProtocol? If so, just set the Url property when you create an instance of the class.
Well, .NET can provide some very useless error messages sometimes. In IIS, the service was configured to AutoDetect cookieless mode. As a result, I had to append "?AspxAutoDetectCookieSupport=1" to the URL. Although that would fix the problem, it was just easier to go to the IIS console, open the properties of the service, go to the ASP.NET tab page, click the "Edit configuration" button, to to "State Management" in the newly popped up screen and change "Cookieless mode" into something other than "AutoDetect"...
Excuse me. Dumb error. Am going to hit myself on the head a few times for this. ;-)
As Jon said, you set the Url, as in:
Namespace.ClassName nwe = new Namespace.ClassName();
nwe.Url = "http://localhost/MyURL/site.asmx";