We have a web service running on the server. We want to use the service in local machine. Could some one kindly give all the steps to get the methods availble in the client.
We have created web methods in the server. And trying to access the same thing on the client. I can literally access those methods using the refernce variable of the server. but when I try to run it , it comes up with run time exception unable to connect to remote server.
I have added the web reference to my client class. What else I am missing. Do I need to do any kind of registration of service with client from command prompt.
I am assuming the client is unable to connect to server because the server is not running when I try to access the methods.
Any one with guidance will be helpful.
Thank you
Hari Gillala
I have added web refernce to this below client class using http://ipaddressofwerver/decisionclass/decisionclass.svc
The code:
try
{
DecisionClass ds = new DecisionClass();
string s = ds.Url;
Label1.Text = s;
string [] a = ds.GetList();
foreach (string i in a)
{
Response.Write(i);
}
}
catch (Exception Ex)
{
Response.Write(Ex.Message);
}
I am assuming the client is unable to connect to server because the server is not running when I try to access the methods.
If it's not running, it won't generate a WSDL either. However, it may have been running while you created the web reference, and then stopped.
Here are some things you can try to track down the problem:
Open the web service's URL, as specified in the web reference, in a regular web browser. This should bring up the web service's documentation page, and if you're running locally and haven't changed the web service's web.config, you can even call some simple methods using the provided test forms
See if you can access the web service with SoapUI or a similar tool.
Also, make sure you're running the web service in IIS, not in the Visual Studio development server - IIS will keep running when you close the project or even Visual Studio, but the development server might not.
Related
I am working on an ERP asp.net mvc 5 web application deployed under iis7. And now I want to implement a new scanning service, which mainly uses powercli and power shell scripts, and scan our network for servers & vms and get their specifications and their statues.
So I am thinking of the following approach:-
1.Since the scanning should be access by only specific users and requires the hosting server to have powercli and other tools installed, so I want to create a new asp.net mvc 5 web application , and deploy it under iis7 instread of modifying my current ERP syste,. Where the new application will have the following action method which will do the scan as follow:-
public ActionResult ScanServer(string token)
{
// do the scan
//send n email with scanning result
}
2.Now inside my current ERP system I can manually initiating the scan by calling the above action method as follow:-
[HttpPost]
[CheckUserPermissions(Action = "", Model = "Admin")]
public ActionResult Scan()
{
try
{
string currentURL = System.Web.Configuration.WebConfigurationManager.AppSettings["scanningURL"];
using (WebClient wc = new WebClient())
{
string url = currentURL + "home/scanserver?token=*******" ;
var json = wc.DownloadString(url);
TempData["messagePartial"] = string.Format("Scan has been completed. Scan reported generated");
}
}
catch (WebException ex)
{
TempData["messageDangerPartial"] = string.Format("scanningservice can not be accessed");
}
catch (Exception e)
{
TempData["messageDangerPartial"] = string.Format("scan can not be completed");
}
Now I did a quick test where I manually started the scan from the ERP and the scanning service deployed under iis worked well.
But I have these questions:-
The scanning service might take 20-30 minutes to complete. So from an architecture point of view is my current approach considered valid ? I mean to initiate a scan by calling an action method from another application ?
Now can i inside the scanning service web application, to force it to call its action method on a timly basis (for example every 4 hours)?
Thanks
Your best option would be to write a windows service to install on the webserver alongside the web app. This windows service can use threads or a timer to execute a long running task (such as scanning your network) at a specified interval and send an email when finished.
You can talk to your service from the app using the database, a config file, or maybe even a registry entry.
If this will not work for you, you can look into some task scheduling apps such as Quartz.NET. If you do use a windows service, I recommend the excellent TopShelf which makes it easy to create and deploy. Here is a nice blog post I found by Scott Hanselman that may help.
I am writing an ETW consumer to listen for ASP.NET events. I have the sample code below working nicely on a Windows 2008 server where it can see the ASP.NET provider. The problem that I am running into is that on my Win7 (64) PC, I do not see the ASP.NET provider so this code shows all the events as “unhandled”.
I have made sure the tracing feature is installed and the applicationhost.config file has the respective values in it.
When I do a logman –query providers, I do not see the
ASP.NET AFF081FE-0247-4275-9C4E-021F3DC1DA35 provider on the PC, but I see this on the Win2008 server that I am testing on.
How can I do one of the two items below:
Add this as a provider to my Win7 PC?
OR
Have the code able to handle this message and provide the manifest in my code. When I set “AFF081FE-0247-4275-9C4E-021F3DC1DA35” as a provider, I do get events but they are from unknown provider. So I am guessing the manifest content is missing.
My sample code is below
static void Test3()
{
var sessionName = "ASPNETMonitorSession";
using (var session = new TraceEventSession(sessionName, null))
{
Console.WriteLine("Starting Test1");
session.StopOnDispose = true;
Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
{
session.Dispose();
};
using (var source = new ETWTraceEventSource(sessionName, TraceEventSourceType.Session))
{
Action<TraceEvent> action = delegate(TraceEvent data)
{
Console.WriteLine("GOT EVENT: " + data.ToString());
};
var registeredParser = new RegisteredTraceEventParser(source);
registeredParser.All += action;
source.UnhandledEvents += delegate(TraceEvent data)
{
if ((int)data.ID != 0xFFFE)
Console.WriteLine("GOT UNHANDLED EVENT: " + data.Dump());
};
session.EnableProvider(new Guid("AFF081FE-0247-4275-9C4E-021F3DC1DA35"));
Console.WriteLine("Starting Listening for events");
source.Process();
}
}
Console.WriteLine("Done");
return;
}
The reason why ASP.NET tracing isn't available in your local machine is because it is not installed. If you look at the perfview help it gives you instructions as to how to enable it.
FYI perfview uses TracEevent to capture traces.
Here it is
ASP.NET Events
ASP.NET has a set of events that are sent when each
request is process. PerfView has a special view that you can open
when ASP.NET events are turned on. By default PerfView turns on
ASP.NET events, however, you must also have selected the 'Tracing'
option when ASP.NET was installed for these events to work. Thus if
you are not seeing ASP.NET events you are running an ASP.NET scenario
this is one likely reason why you are not getting data.
To turn on ASP.NET Tracing
The easiest way to turn on tracing is with the DISM tool that comes
with the operating system. Run the following command from an
elevated command prompt
DISM /online /Enable-Feature /FeatureName:IIS-HttpTracing
Note that this command will restart the web service (so that it takes effect),
which may cause complications if you ASP.NET service handles long
(many second) requests. This will either force DISM to delay (for a
reboot) or abort the outstanding requests. Thus you may wish to
schedule this with other server maintenance. Once this configuration
is done on a particular machine, it persists. You can also do
this configuration by hand using a GUI interface. You first need to
get to the dialog for configuring windows software. This differs
depending on whether you are on a Client or Server version of the
operating system.
On Client - Start -> Control Panel -> Programs -> Programs and
Features -> Turn Windows features on or off
-> Internet Information Services -> World Wide Web Services -> Health and Diagnostics -> Tracing On Server - Start -> Computer -> Right
Click -> Manage Roles -> Web Server (IIS) -> Roll Services Add Role
Services Health and Diagnostics -> Tracing
Hope this helps.
I have a ASP.NET WebApp that contains some ASMX webservices. We recently migrated to load balanced Windows 2008 servers from a Windows 2003 server. The new servers sit behind some F5 appliance for the load balancing (that's all I know about it!).
We can reach the built in ASP.NET POST test (example: http://webapp.company.com/webservices/Person.asmx?op=GetPerson) but invoking it from that test page fails (page not available). A new tab in the browser opens with the same url, but with a port number appended on the end: http://webapp.company.com:50831/webservices/Person.asmx?op=GetPerson. When I put that URL(with port) into my browser, it fails as well. Heck, http://webapp.company.com:50831 isn't reachable at all.
We didn't get that on our previous server. I setup my own personal webserver on a personal Windows 2012 server and tested the same code on there and it worked. So I'm thinking it has to do with the load balancing.
Unfortunately, I have no control over the web servers our company offers for hosting internal applications. I don't get to touch the IIS either. All I get is a file path to publish my files to. The hosting organization is telling me my ASP.NET WebApp code is appending the port number, but I don't think that's right. It only occurs on those load balanced servers!
Has anyone else ran into this before when invoking ASMX or WCF that's hosted behind a F5 appliance?
The IT group that maintains those servers didn't have any answers for us, but we were able to verify those odd ports were in fact being assigned by the F5 appliances. We ended up using a port rewriter as a workaround until the group that maintains the web servers can alter the configuration. The code we used is below which is taken straight from the URL below where they were discussing the same problem behind the same F5 appliance (BigIP).
http://www.justskins.com/forums/port-mapping-a-web-51075.html
public class WSDLAddress : SoapExtensionReflector
{
bool bFirstTime = true;
public override void ReflectMethod()
{
if (!bFirstTime) return;
bFirstTime = false;
SoapAddressBinding sabAddress = ReflectionContext.Port.Extensions.Find(typeof(SoapAddressBinding)) as SoapAddressBinding;
string sPort = ConfigurationSettings.AppSettings["myPort"];
UriBuilder uriLocation = new UriBuilder(sabAddress.Location);
uriLocation.Port = Int32.Parse(sPort);
sabAddress.Location = uriLocation.Uri.AbsoluteUri;
}
}
I have two PCs conected with a LAN. Firewall ports are opened.
I'm running a WebService on A machine, using IIS. Of course, I can access the WebService (on A) through the Web Browser on the B machine, so I'm sure the WebService can be accessed remotely.
Now, I'm running a console app on B machine, developed in vb.net, which will access the WebService of A machine.
Both, the console app and the WebService, has been developed on VS2010.
Creating the reference on the project, I can see and use the WebService. But I need to specify on code the URI due to the WebService may change its location.
The code indicating the URI manually:
Dim myService As New MiServicioWeb.WebServiceSoapClient("192.168.1.13:8080")
This line throw an exception with the message that did not find any element with the name indicated. I have tried too, without success, the following lines:
This one:
Dim myService As New MiServicioWeb.WebServiceSoapClient("192.168.1.13")
And this one:
Dim myService As New MiServicioWeb.WebServiceSoapClient("192.168.1.13:8080/ServicioWeb.asmx")
But the result is always the same.
Some user (raja) wrote an answer a few days ago indicating that this should work, but I don't know the reason why does not work in my case.
As I said before, if I create the reference on the project, and I use the following line of code:
Dim myService As New MiServicioWeb.WebServiceSoapClient()
It works!, but what I need is to set the URI manually...
Some help will be thankful.
if not already present, you need to modify the proxy class to have a constructor that can take a Uri and set it. This Uri needs to be supplied to the proxy.
Dim uriFromConfig as String;
// read uriFromConfig from config or set it accordingly.
Dim myService As New MiServicioWeb.ServicioWebSoapClient(uriFromConfig);
this way, any ASMX can be called, as long as the right Uri is provided.
in summary to call a webservice hosted on machine with IP a.b.c.d from another machine:
Give the Proxy Uri with the IP Address. a.b.c.d
Open the port (50594) you're using in the machine hosting the web service from the Firewall settings.
Verify if the asmx is accesible by typing http://a.b.c.d:50594/ServicioWeb.asmx from the browser of the client machine. (not the machine hosting the web service)
if #3 is successful, then you'll see a nice page on the browser.
your client app should also be able to connect now.
Bellow is my code from asp.net service which is trying to run some external exe. It works fine from my Visual Studio on win 7, but fails on my server (server 2008).
Myapp.exe reports back eror that account under which is runned doesn't have sufficiet priviliges.
List<ProcInfo> allProcesses = new List<ProcInfo>();
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = binPath + #"\myApp.exe";
pInfo.WindowStyle = ProcessWindowStyle.Hidden;
pInfo.CreateNoWindow = true;
pInfo.UseShellExecute = false;
pInfo.RedirectStandardOutput = true;
string exitMsg = "";
int exitCode = 1;
try
{
using (Process proc = Process.Start(pInfo))
{
exitMsg = proc.StandardOutput.ReadToEnd();
proc.WaitForExit(1000);
exitCode = proc.ExitCode;
}
}
Resource pool on the server runs under account with sufficient priviliges and I also tried to use same account in code to start service with those same credentials and still nothing.
I have been told that account under which asp.net worker thread runs impose some additional limitations. So even if resource pool runs under appropriate account, you still won't have sufficient priviligies.
I also found something about using pInvoke and win32 api calls as the only way to run external code from asp.net service. But I don't have any win32 api knowlege nor did I found exples of this.
I would be very grateful for any tip/example how to run external exe under specified account from asp.net service.
If the account the worker process is runnning under lacks sufficient privelages then you have a few options.
You can either use impersonation in your code:
WindowsIdentity.Impersonate Method
Or configure IIS to run the application under a user account with the required privileges.
Here is an article which explains different methods of impersonation security:
Understanding ASP.NET Impersonation Security
If you do not feel confident implementing the user impersonation code yourself, here is a link to a codeproject article:
A small C# Class for impersonating a User