Catching all unhandled exceptions in WCF web service in c# - web-services

I need to catch all unhandled exceptions in my web service.
My service is created with Visual Studio Express 2013 for Web and it is a WCF service style using c#.
I already do that in Android but I have no idea how to do it with the WCF service.
Any ideas?

As far as I know it is not possible to do that in code as you can do in Android but you can enable tracing in the Web.config file this way:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...your other settings...
<!-- Trace: -->
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Error"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "C:\Logs\MyTraces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
The switchValue="Error" can be changed depending on the level you want.
More info:
http://www.topwcftutorials.net/2012/06/4-simple-steps-to-enable-tracing-in-wcf.html
https://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx

Related

ASP.NET Core 2.0 how to increase IIS Express request timeout in launchSettings.json

I have an ASP.NET Core 2.0 API that I am trying to debug using VS2017 / IIS Express on my local Win10 dev computer and I am running into an issue with IIS Express in that it is hitting the response timeout default of 2 minutes before my process can complete in my API, thus returning a 502.3 - Bad Gateway message.
I process continues to run in my API and completes after 3 minutes and 50 seconds. So, I need to increase the request timeout for IIS Express.
Most of the examples I have found on the web talk about using the web.config, for example;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore requestTimeout="00:20:00" processPath="dotnet" arguments=".\MyAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
... but from what I understand, An ASP.NET Core 2.0 API running on the local IIS Express doesn't uses a web.config from my project bt rather, it relies on launchSettings.json in the project. However, I have not been able to find anything on the web that talks about launchSettings having any settings values for increasing default timeouts.
Just to confirm, I tried putting a web.config file, like what I listed above, in my project's wwwroot folder, but it made no difference. This worked on my deployed solution in Azure (see related Stack Overflow post) but doesn't in IIS Express on my local dev.
This seems like it should be a simple task but so far I have not had any luck finding a solution.
Any ideas?
EDIT 5/27/18 - SOLUTION
IIS Express with ASP.NET Core 2.0 uses a file similar to a web.config called applicationhost.config, which is located in the project root/.vs/config folder. This file has a
<configuration><Location> ... <location</configuration>
section similar to what I have listed below. This section has the
<aspNetCore ... />
node where I was able to apply the requestTimeout value. By setting that, my dev system was able to get past the default 2 minute timeout.
<location path="MyAPI">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<httpCompression>
<dynamicCompression>
<add mimeType="text/event-stream" enabled="false" />
</dynamicCompression>
</httpCompression>
<aspNetCore requestTimeout="00:20:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="false" />
</system.webServer>
</location>
You misunderstood the concepts.
launchSettings.json is only used by Visual Studio to determine how to run your web project. (More info in my blog post)
IIS Express still relies on web.config to read the settings, as that's the only file it understands.

AXIS error: There is no SOAP service at this location

Note: I could not find a straight-forward answer to this problem so I will document my solution below as an answer.
I generated the server-side part of a webservice from a wsdl using Axis 1.4 and
the axistools-maven-plugin. The Axis servlet is mapped to /services/*, the
service is configured in WEB-INF/server-config.wsdd as follows:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="TestService" style="document" use="literal">
<namespace>http://example.com/testservier</namespace>
<parameter name="className" value="com.example.TestServiceImpl"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="scope" value="Session"/>
</service>
</deployment>
When I deploy this web application to Tomcat and access
http://localhost:8080/testservice/services a list of deployed services is
returned.
And now... Some Services
TestService (wsdl)
TestService
Clicking on wsdl should return the description for this service but results in the following error page:
AXIS error
Could not generate WSDL!
There is no SOAP service at this location
The server-config.wsdd was missing a neccessary configuration setting.
<transport name="http">
<requestFlow>
<handler type="java:org.apache.axis.handlers.http.URLMapper"/>
</requestFlow>
</transport>
It seems the URLMapper is responsible for extracting the service name from
the url, without it axis does not know which service to invoke. This is sort of
documented in the axis faq:
This mechanism works because the HTTP transport in Axis has the URLMapper (org.apache.axis.handlers.http.URLMapper) Handler deployed on the request chain. The URLMapper takes the incoming URL, extracts the last part of it as the service name, and attempts to look up a service by that name in the current EngineConfiguration.
Similarly you could deploy the HTTPActionHandler to dispatch via the SOAPAction HTTP header. You can also feel free to set the service in your own custom way - for instance, if you have a transport which funnels all messages through a single service, you can just set the service in the MessageContext before your transport calls the AxisEngine
This makes it sound like the URLMapper would be configued by default which does not seem to be the case.
When I had this problem, it was caused by using the wrong URL.
I used http://localhost:8080/axis/services/AdminWebService?wsdl instead of http://localhost:8080/axis/services/AdminService?wsdl.
AdminWebService must be changed to AdminService.
You better build the server-config.wsdd automatically with the goal "admin". See the documentation about this plugin:
http://mojo.codehaus.org/axistools-maven-plugin/admin-mojo.html
It is very difficult to generate the server-config.wsdd manually.
Example:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<filename>${project.artifactId}.wsdl</filename>
<namespace>http://server.ws.xxx</namespace>
<namespaceImpl>http://server.ws.xxx</namespaceImpl>
<classOfPortType>XXXWebService</classOfPortType>
<location>http://localhost:8080/XX/services/XXXWebService</location>
<bindingName>XXServiceSoapBinding</bindingName>
<style>WRAPPED</style>
<use>literal</use>
<inputFiles>
<inputFile>${basedir}\src\main\webapp\WEB-INF\xxxx\deploy.wsdd</inputFile>
<inputFile>${basedir}\src\main\webapp\WEB-INF\xxxx\deploy.wsdd</inputFile>
</inputFiles>
<isServerConfig>true</isServerConfig>
<extraClasses></extraClasses>
</configuration>
<executions>
<execution>
<goals>
<goal>java2wsdl</goal>
<goal>admin</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
I had the same problem recently.
Solution :
In my case, I was using Axis 1.4 and was deploying the application on tomcat. However, for some reason the generated server-config.wsdd was not getting packaged in the war and hence was not getting deployed on tomcat. Once, I ensured this is happening, it started working fine for me.
you ensure server-config.wsdd in your package, you can put this file to resources or you can set in your pom.xml via maven which files will be in the package
server-config.wsdd must be valid and correct tags or necessary config is exist so below rows must be in it;
<handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/>
<handler type="java:org.apache.axis.transport.local.LocalResponder" name="LocalResponder" />
<transport name="http">
<parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler" />
<parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler" />
<parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler" />
<requestFlow>
<handler type="URLMapper" />
<handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
</transport>
<transport name="local">
<responseFlow>
<handler type="LocalResponder" />
</responseFlow>
</transport>

Configuration for downloading large DIME attachments via C# DLL from JasperServer web service

I'm building a MVC2 .Net web app to download and view reports stored on Jasperserver. I've built a web service client library to access the Jasperserver web service. Jasper works with DIME attachments so I'm using Microsoft.Web.Services2.
My MVC2 app works fine with smaller reports but when I try and pull down a 90 page report in html (~9mb) I run into this error:
WSE352: The size of the record exceed its limit.
The post here shows the following for app.config settings of my client app:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="microsoft.web.services2" type="Microsoft.Web.Services2.Configuration.WebSer vicesConfiguration, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</sectionGroup>
</configSections>
<applicationSettings>
...
</applicationSettings>
<microsoft.web.services2>
<messaging>
<maxRequestLength>-1</maxRequestLength>
</messaging>
</microsoft.web.services2>
</configuration>
After making these changes I'm still running into the same error "WSE352". My question is should the above app.config changes to my library be sufficient for my MVC app to download large reports? Or do I need to make changes to the web.config of my MVC app?
Any help would be greatly appreciated!
Yes, you do need to add configurations to the web.config of your MVC app!
After re-reading the linked post and doing some experiments my problems where mostly copy/paste related.
Here is the relevent parts of the app.config in my library:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="microsoft.web.services2" type="Microsoft.Web.Services2.Configuration.WebServicesConfiguration, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<microsoft.web.services2>
<messaging>
<maxRequestLength>-1</maxRequestLength>
</messaging>
</microsoft.web.services2>
</configuration>
And the relevant parts of web.config of the MVC app:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="microsoft.web.services2" type="Microsoft.Web.Services2.Configuration.WebServicesConfiguration, Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<microsoft.web.services2>
<messaging>
<maxRequestLength>-1</maxRequestLength>
</messaging>
</microsoft.web.services2>
</configuration>

How to report progress of a web service on windows mobile client?

I have tried to implement progress reporting using a soap extension as described at the following links:
stackoverflow
codeproject
However, my "ProgressUpdate" method is not being called, and I believe that is because I haven't got an app.config file in my Windows Mobile project to tell the web service calls to be processed by the SOAP Extension. How can do it in Windows Mobile? This is the sample config file used in the article:
<?xmlversion="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<webServices>
<soapExtensionTypes> <add
type="SoapExtensionLib.ProgressExtension, SoapExtensionLib"
priority="1" group="High" />
</soapExtensionTypes>
</webServices>
</system.web>
</configuration>
I figured out how to do this by adding a custom attribute to the method inside the generated proxy class. The custom attribute is derived from SoapExtensionAttribute.
I got the information at MSDN
Problem now is that I have to remember to add the attribute back in if I refresh the web service reference..............

webservice using security UserNameToken

I am trying to resolve a problem we have using glassfish V2 to publish a simple web service using a plain UserNameToken for security reasons. Since we were using Netbeans 6.5 to archive this we were looking into this tutorial.
Therefore the following steps were done:
In our dev environment we installed the Sun Java(TM) System Access Manager and can administer this through the admin console as well as through the Netbeans IDE. All good. The example from the tutorial worked perfect so we thought we are in a good position to move on.
After changing the security options for our web service we published this on our test environment without any Netbeans installed.
After that the following steps were done:
deploying the service
configure the realm in Access Manager for the IP address
setup the expected user to access the web service.
When our partner is now accessing the web service the actual web service code is not accessed and we always find in the server logging that the security header was not understood.
This is the message we receive at the server:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-10034404">
<wsu:Created>2009-01-19T16:33:38.537Z</wsu:Created>
<wsu:Expires>2009-01-19T16:34:08.537Z</wsu:Expires></wsu:Timestamp><wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-10034094">
<wsse:Username>myUser</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">myPasswd</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
<wsa:MessageID soapenv:mustUnderstand="0">uuid:ecc3b150-e646-11dd-96e5-9f80a576275b</wsa:MessageID>
<wsa:To soapenv:mustUnderstand="0">http://62.154.241.166:8080/HTNGService/WebServiceForTrustService</wsa:To>
<wsa:Action soapenv:mustUnderstand="0">http://webservice.trustinternational.com/ws/services/Htng2ReservationService</wsa:Action>
<wsa:From xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing" soapenv:mustUnderstand="0">
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address></wsa:From>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body></soapenv:Envelope>
our wsit.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="WebServiceForTrustService" targetNamespace="http://wstrust/" xmlns:tns="http://wstrust/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp1="http://www.w3.org/ns/ws-policy" xmlns:fi="http://java.sun.com/xml/ns/wsit/2006/09/policy/fastinfoset/service" xmlns:tcp="http://java.sun.com/xml/ns/wsit/2006/09/policy/soaptcp/service"
>
<message name="otaHotelResNotif"/>
<message name="otaHotelResNotifResponse"/>
<portType name="WebServiceForTrust">
<operation name="otaHotelResNotif">
<input message="tns:otaHotelResNotif"/>
<output message="tns:otaHotelResNotifResponse"/>
</operation>
</portType>
<binding name="WebServiceForTrustPortBinding" type="tns:WebServiceForTrust">
<wsp:PolicyReference URI="#WebServiceForTrustPortBindingPolicy"/>
<operation name="otaHotelResNotif">
<input/>
<output/>
</operation>
</binding>
<service name="WebServiceForTrustService">
<port name="WebServiceForTrustPort" binding="tns:WebServiceForTrustPortBinding"/>
</service>
<wsp:Policy wsu:Id="WebServiceForTrustPortBindingPolicy">
<wsp:ExactlyOne>
<wsp:All/>
</wsp:ExactlyOne>
</wsp:Policy>
</definitions>
Does anyone has any idea what configuration might be missing here?
We also realised that in the IDE after turning the security (AM security) on there was a file created under configuration files/ amserver called amconfig.xml.
This file we can't find on the webserver after deploying the service nor in the *.war nor under addons/amserver or so.
The file internally looks like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:AMConfig xmlns:ns2="http://identity.netbeans.org/access_manager_config_1_0">
<ProviderConfig type="WSP" name="WebServiceForTrustService">
<SecurityMechanism uri="urn:sun:wss:security:null:UserNameToken-Plain"/>
</ProviderConfig>
</ns2:AMConfig>
since the information is already in sun-web.xml which is published on the server I think that should not be the problem but might be helpful for you.
since we worked further on the above here a few new things even if it isn't solved.
The example tutorial was rebuild and deployed on the test-server. Client and Server Test app. Both are working fine when started locally on the test-server.
If we configure how ever a client from remote to use the same web-service with the same security information, we find the same error like with our other application.
Therefore I assume it has something to do with the configurations o Access Manager, but no idea which one.
I hope that helps anyone to help me.
Thanks!