Get app that is consuming web service - c#

How do I extract/get the URL name that is consuming my web service?
For say, i have a .asmx web service, consumed by .aspx web app, in my .asmx code, i need to get that web app's url? Is that any way doable?

You just need to inspect the HTTP request.
HttpContext.Current.Request.UrlReferrer

Related

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.

Web API Missing on deployment

So I have a C# MVC Web API and Web Application that is an all-in-one project. I've created something similar to this in the past but the Web Application and Web API were two different projects with two different URLs.
For example:
The Web Application would be hosted at mywebsite.com/webapp
The Web API would be hosted at mywebsite.com/webapi
Any time I wanted to call the Web API from the Web Application all I had to do is send an Ajax request using the URL mywebsite.com/webapi/api/getdata
However, with my current project it's all-in-one. So in testing I would simply call /api/getdata and it would work just fine in Visual Studio debug. But when I deploy this site for testing and actually host it all my API calls are met with HTTP 404 errors.
So how do I call the Web API when the Web API doesn't have it's own distinct URL?
In IIS I converted the folder to an application and then made sure to switch the calls from
mywebsite.com/api/getdata
to
mywebsite.com/myproject/api/getdata
and it's working now.
Credit to #mxmissile for pointing it out.

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.

Redirection before invoking web method of asmx web service

I have a asmx web service hosted at US as well as Canada. But there are few Canadian clients which points to US web service and I am not able to make any changes at client side to make them point to Canadian web service.
Is there any way I can redirect calls coming to US Web Service (Before web method hit) to Canadian web service? May be some HttpModule or SoapExtensions?
I ended up doing what I didn't want to.
I added proxy of own web service and called it by overwriting URL in each web method. I structured it by adding factory class.
Thanks!

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.

Categories