Web service takes long time to run the first time - c#

I am new to writing and deploying web services and I have a web service that when I run it from my C# applications, it will take 4-8 seconds to respond the first call. Subsequent calls are in the half second range. If I call the web service from internet explorer, it returns immediately.
My Web service is a Soap web service running on windows web server 2008 server. I have been looking for a solution for several days and nothing I have tried has helped. The 2 things have tried that don't appear to work is precompile the XmlSerializers (Generate serialization assembly is on) and precompile the web service using aspnet_compiler. The output of aspnet_compiler I copy to the server and paste into the appropriate folder.
My application is calling the web services by using the auto generated code web reference code created when you use the Add Web Reference wizard.
Is there something else I can try?

A common culprit is checking of Publisher Evidence (basically, assembly signatures) in the absense of open connectivity to the internet.
Try adding the following line to your ASPNET.CONFIG or APP.CONFIG file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
See for background and details online articles, e.g.
http://blogs.msdn.com/b/pfedev/archive/2008/11/26/best-practice-generatepublisherevidence-in-aspnet-config.aspx

Related

How to get a C# azure service that uses ChromeDriver to work in an Azure Cloud Service

I've written a C# Azure cloud service that uses Selenium.WebDriver.ChromeDriver but it doesn't work when I deploy it to Azure (Locally it runs fine - probably because I have Chrome installed).
I deploy chromedriver.exe with my service but it fails because chrome.exe isn't found.
I've tried deploying a copy of chrome.exe but that didn't work. I also tried adding the GoogleChrome nuget package but this also didn't work.
Anyone know a way to get a C# azure service that uses Selenium/Chromedriver to work?
Three things you'll need to get this to run on an Azure cloudservice
ChromeSetup.exe file included in your CloudService/Roles/Role directory
A line in your service definition file to call a startup script that runs the above file
That startup script included in your worker role's project
To add ChromeSetup.exe, right click on the name of your role beneath the cloud service and just "Add Item" and find where you downloaded the chrome installer last.
The startup task is added by going into the ServiceDefinition.cdef file--example from a recent project below.
<WorkerRole name="WebReportDownloader" vmsize="Small">
<Startup>
<Task commandLine="Initialization\Startup.cmd" executionContext="elevated" taskType="simple">
<Environment>
<Variable name="MyVersionNumber" value="1.0.0.0" />
</Environment>
</Task>
</Startup>
The script the above task calls is pretty simple and logging anything to a text file is optional from my reading:
ECHO The current version is %MyVersionNumber% >> "%TEMP%\StartupLog.txt" 2>&1
START ChromeSetup.exe
EXIT /B 0
Hopefully this saves you some of the grief I ran into while piecing together several resources...
I found another way of doing this without having to install Chrome - instead of using Chrome I ended up using Chromium.
For this I just downloaded the Chromium archive from https://chromium.woolyss.com/download/ then have it extract to my binaries directory - this still has Chrome.exe binary but doesn't need installing

.Net WCF SVC Info Page and Fully Qualified Server Names

I have two servers on which the identical .net 2.0 WCF service code has been deployed. On both servers the code is running in a dedicated web application with a dedicated application pool assigned to it. Both the web applications and the application pools are configured, as near as I can tell from IIS, identically on both machines. Furthermore, both machines have the same exact versions of the .net framework installed.
On one server the SVC info page served up by IIS lists a fully qualified machine name but the other lists a non-fully qualified machine name. I've provided sample URLS to the info page and the results below:
://server1:1995/Service.svc yields:
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 ://server1.domain.com:1995/Service.svc?wsdl
://server2:1995/Service.svc yields:
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 ://server2:1995/Service.svc?wsdl
I wouldn't normally care about this except for the fact that a packaged product I'm using appears to insist that the URL I give it for the WSDL match exactly what the info page states and I can't figure out why it needs to be different for these two (seemingly identical) machines.
Any help would be greatly appreciated!
(please note I had to delete "http" from the hyperlinks above to keep StackOverflow happy)
The solution here was to add the following line to the SVC web.config file. The behavior was inconsistent across different versions of IIS (and possibly the .net CLR) but adding this line normalized the behavior:
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

Calling WCF service from class library: App.Config vs Web.Config?

From an existing WebApplication I use to make calls to WCF services. Proxies for these services was created using Add Service Reference menu. Thus generating >> Web.config in this project.
I have added another class library project to the solution. This project also adds reference to the service. Thus generating >> App.Config file in this project.
I understand, in an N-Tier application, we should have common gateway to the service. Just out of curiosity I would like to know -
For WCF calls originated in WebApp, propagated to class library which config file (App/Web) would be referred
for locating client endpoint configurations ?
The web.config file will be used for locating the service.
The reason is because in this case, the app domain belongs to the web app, not the class library, and the default config file for this app domain is the web.config.
#musefan is correct. It is the web.config that is used.
If you want to, you can split some confuguration sections into seperate files and reference them from the main web.config. You might want to do this so you can maintain the WCF client and server config in a single place to ensure they are consistent.
foe example, if you want to seperate out the <client> section, you would do this:
<client configSource="client.xml" />
Where client.xml is a file containing the relevant client config information.
This blog post tells you how to do it in a bit more detail.
http://blog.andreloker.de/post/2008/06/keep-your-config-clean-with-external-config-files.aspx

Clear Username Binding (Unable to automaticalli debug wcf service)

Recently I've read an article about own WCF binding with Username and Password authentication.
Here is an article: http://webservices20.blogspot.ru/2008/11/introducing-wcf-clearusernamebinding.html.
This project "Clear Username Binding" works well. But the problem for me is that I want the WCF server to be host in WCF Service Host. (Like if you create in VS any service library from the template it will be run in WCF Service Host). I've done the next thing. I've created a new project (service library) and simply copy your service and contract to this new project. Then I copied the app.config system.serviceModel section and added referenced to ClearUserNameBinding project and MyUserNameValidator. That's all
Next, I run the client application. Everything was ok. WCF Service Host had been started and client application ended as I expected. But the problem is that now if I put a breakpoint somewhere in the service implementation (let it be somewhere inside of the EchoString function) and run again I always get a message in VS IDE "Unable to automatically debug WCFServiceLibrary". I really don't know what to do with this error and how to get rid of it, because I need the debugging to be available for me.
P.S. This error is appearing only when I use ClearUserNameBinding. If I use for example wsHttpBinding it works perfect. And of course I have <system.web> <compilation debug="true" /> turned on in my config file
Thanks in advance!
In visual studio put a breakpoint in the first line of the client and attach to the process "WCF service host". Then you could debug into its breakpoints. Not sure how to do it w/o attaching to another process.
Also you could try to use CUB not as a separate binding but as a custom binding. You will need to create the custom binding from code. Pseudo code:
var b = new CustomBinding();
b.elements.add(new TextEncodingElement())
b.elements.add(new SecurityElement() {SecurityMode="UsernameOverTransport"})
b.elements.add(new AutoSecuredHttpTransportElement())

How to programmatically add domain service end point to web.config

I am in need of help with manipulating the web.config of a site programmatically via C#. The site in question hosts a Silverlight 5 application which communicates with the server runtime via WCF RIA services.
The code that I am writing is part of a bootloader for an automated build-deploy-test scenario aimed at testing the WCF Ria service stack. The issue at question is that in order to test the services properly the unit test code needs to be able to communicate with the Ria Services via a new soap endpoint.
To effectively make this work the site needs a copy of the Microsoft.ServiceModel.DomainServices.Hosting dll in it's bin folder, and a new soap endpoint which would make the domain services config section look like the following:
<system.serviceModel>
<domainServices>
<endpoints>
<add name="OData" .../>
***<add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>***
</endpoints>
</domainServices>
</system.serviceModel>
While I do believe I could modify the web.config via the C# xml api, I was wondering if there is another way to do so via the ConfigurationManager?
I would do config manipulation as part of the build script.
I am currently using YDeliver as the build/deploy framework in my project and since it runs on top of Powershell, I manipulate XML using the xml api in posh.

Categories

Resources