WCF webservice fails after "extracting interface" - web-services

I am new to WebServices, and have a simple question.
I wrote a "Hello World" Service with Visual Studio 2017:
ServiceAjax.svc.cs:
namespace WebServiceTest
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceAjax
{
[OperationContract]
[WebGet]
public string DoWork()
{
return "Hallo World";
}
}
}
the ServiceAjax.svc reads as this:
<%# ServiceHost Language="C#" Debug="true" Service="WebServiceTest.ServiceAjax" CodeBehind="ServiceAjax.svc.cs" %>
Running this works fine.
Now i read it's the way to go to declare an Interface for the Service.
Nearly every example does this ..., so i tried:
ServiceAjax.svc.cs:
namespace WebServiceTest
{
[ServiceContract]
public interface IServiceAjax
{
[OperationContract]
[WebGet]
string DoWork();
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceAjax: IServiceAjax
{
public string DoWork()
{
return "Hallo World";
}
}
}
Running this i get an error:
It's german, so my translation might be not excatly as the english message:
"From http://localhost:58513/ServiceAjax.svc no metadata could be loaded ..."
I Little bit below he tells me:
WebServiceTest.ServiceAjax wos not found in the List of contracts implemented by ServiceAjax
So, it must be a dump foult, cause i cant explain why extracting an Interface blows the Service, i sure missed something simple.
But i cant find a difference to the "simple WCF Web HTTP Service" samples in the net.
Ideas?
Update: I added this to an existing ASPX-Project, not a "clean" wcf Project ....

I found the answer myself (after earning the Tumbleweed badge ...)
There was one line missing in the WebConfig
<endpoint address="mex"
binding="mexHttpBinding"
name="mex"
contract="IMetadataExchange" />
I had tried with different "Factorys" in the SVC-Markup, which did not work.
Perhaps havent found the right one ...
i.e.
<%#ServiceHost language=c# Debug="true" Service="WebServiceTest.ServiceAjax"
Factory=System.ServiceModel.Activation.WebScriptServiceHostFactory%>
Adding the Config manually and adding to it did the trick after all.
I followed the steps in
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-configuration-to-add-an-aspnet-ajax-endpoint
This lead to the "cant load metadata" Problem which i could fix with the line on Top (mex endpoint).
Why mircosoft [sic] did not point that out, i dont know ...
And why this starts beeing needed when using an interface i dont know neither.
But I stumbled about more occasions, when he needed that, i.e, AJAX Scripting Manger, which needs the Namespace-Argument in the Servicedeclaration too:
[ServiceContract(Namespace = "AJAXService")]
Below what i added to web.config (allready included Lines where dropped 4 shortage
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="myDataAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="myServiceTypeBehaviors"
name="WebServiceTest.ServiceAjax">
<endpoint address=""
behaviorConfiguration="myDataAspNetAjaxBehavior"
binding="webHttpBinding"
name="ZESData"
contract="WebServiceTest.IZESData" />
<endpoint address="mex"
binding="mexHttpBinding"
name="mex"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>

Related

WCF 4 routing service throws handler error

I am trying to use WCF 4 routing declaratively to redirect one branch of my (REST) web services to an alternate server. I configured WCF's System.ServiceModel.Routing.RoutingService to route http://oldserver:81/FileService/ calls to http://newserver:82/FileService/, but when I try to access the redirected service, all it does is throw the error
Handler "HttpLogging" has a bad module "HttpLoggingModule" in its module list
I can enter URLs to the new service in my browser and they work fine, but URLs to the old service (to be re-routed) fail.
I have added the following routing configuration into my web service application:
<configuration>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="routingConfig">
<!-- Specify the routing table to use. -->
<routing filterTableName="routingTable1" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<!-- WCF routing table -->
<routing>
<filters>
<filter name="FileFilter1" filterType="EndpointName" filterData="FileService"/>
</filters>
<filterTables>
<filterTable name="routingTable1">
<add filterName="FileFilter1" endpointName="FileService" />
</filterTable>
</filterTables>
</routing>
<client>
<!-- Destination endpoint defining the base URL where File messages will be routed. -->
<endpoint name="FileService"
address="http://newserver:82/FileService/"
binding="webHttpBinding"
contract="*" />
</client>
<services>
<!-- WCF routing service. -->
<service name="System.ServiceModel.Routing.RoutingService" behaviorConfiguration="routingConfig" >
<host>
<baseAddresses>
<!-- The service endpoint to be redirected. -->
<add baseAddress="http://oldserver:81/FileService" />
</baseAddresses>
</host>
<!-- Define the endpoints of the service to receive messages. -->
<endpoint name="reqReplyEndpoint" binding="webHttpBinding" contract="System.ServiceModel.Routing.IRequestReplyRouter" address="" />
</service>
</services>
There is no longer a FileService service in the application, except the one that should be exposed by the routing service.
I've tried:
filter types of MatchAll, EndpointAddress, and PrefixEndpointAddress;
various forms of the old service addresses;
different names for filters, routing tables, services;
renaming contracts.
None of it gets my client to call the redirected service, much less even any indication that the routing service is operational or even configured at all.
How do I make the routing actually work? Failing that, how would I debug it so I can determine what to fix?
The general problem I see is that you are trying to route REST calls with Routing Service, which is not supported. MSDN reference:
https://msdn.microsoft.com/en-us/library/ee517423.aspx
The Routing Service does not currently support routing of WCF REST
services. To route REST calls, consider using System.Web.Routing or
Application Request Routing
(http://go.microsoft.com/fwlink/?LinkId=164589).
Blockquote

Mass Transit with Quartz / Scheduling - Are there any example implementations out there?

I have searched high and low for an example implementation or blog post on how to use Mass Transit's Quartz integration (https://github.com/MassTransit/MassTransit-Quartz).
At the moment I have to make do with just looking at the unit tests that come with the code base and I'm not making much progress.
Are there any examples or good blog posts out there to help me get started with Mass Transit and Quartz Scheduling?
This example lets you persist a MassTransit scheuled message in a SQL database. Out of the box, MassTransit only persists in memory without some config changes.
First of all you need a subtle change to your app/web.config file to include the following 2 blocks:
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<quartz>
<add key="quartz.scheduler.instanceName" value="MassTransit-Quartz" />
<add key="quartz.scheduler.instanceId" value="AUTO" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="4" />
<add key="quartz.threadPool.threadPriority" value="2" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.useProperties" value="false" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" />
<add key="quartz.jobStore.clustered" value="true" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.dataSource" value="quartzDS" />
<add key="quartz.dataSource.quartzDS.connectionString" value="Server=(local);Database=Quartz;Integrated Security=SSPI" />
<add key="quartz.dataSource.quartzDS.provider" value="SqlServer-20" />
Then, in your local SQL, create a new database named "Quartz", download the quartz.net source and locate the database script
"tables_sqlServer.sql"
run this against your Quartz local database to create the schema.
Now you have everything ready to persist scheduled messages in the database, you need to subscribe these two consumers from the MassTransit Quartz integration library:
var scheduler = CreateScheduler();
sb.SubscribeConsumer(() => new ScheduleMessageConsumer(scheduler));
sb.SubscribeConsumer(() => new CancelScheduledMessageConsumer(scheduler));
Where scheduler is an IScheduler:
static IScheduler CreateScheduler()
{
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
return schedulerFactory.GetScheduler();
}
and sb is your servicebus of type IServiceBus.
Finally, in your code call:
Bus.ScheduleMessage(SchedulePeriodInSecondsFromNow, MessageToSchedule);
And have a consumer for the "MessageToSchedule" type.
If you open up the database and query the QRTZ_TRIGGERS table, you will see jobs appearing there and in QRTZ_JOB_DETAILS.
Hope this helps!

Integrating Simplemembership in an existing webapplication painlessly

Could someone please elaborate on how to implement simplemembership into an existing web application. All the blogs are very confusing and lack detail. There's one that I found that doesn't appear to work. I have an existing blog app that I've build and I'm looking for a painless way to use simplemembership..
Please help..
Thanks
If you are using MVC4, as you mentioned in tags:
1) Create new MVC4 Internet WebApplication
2) Copy from it:
a)AccountController from Controllers folder
b)AccountModels from Models folder
c)Account folder from View folder
4) Past it to your application
5)Change everythere namesoaces to your application
6)Modify web.config:
Add (you may copy it from new application):
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="gunselEntities" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="3" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
</system.web>
7) Add Aspnet membership tables to your database. Navigate to the wizard(C:\Windows\Microsoft.NET\Framework[framework version]\aspnet_regsql) and launch it. It will run special wizzard, which helps to add tables.

copy complexType to message in BPEL

I am using Apache ODE to write some simple BPEL's to connect 2 web services.
One of the WSDL files of my two services contains this complex type:
<types>
<t:schema targetNamespace="http://ws.panos.com/" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<t:complexType name="myObject">
<t:sequence>
<t:element minOccurs="0" name="str" type="t:string" />
</t:sequence>
</t:complexType>
</t:schema>
How do I make a copy from a service return message (which is just a xsd:string) to the input of a message (inside "str" of type "myObject"?
I have tried to do this, but doesnt seem to work:
<assign name="assign_2">
<copy>
<from variable="wsA_output" part="return"/>
<to variable="wsC_input" part="arg0" query="/arg0/str"/>
</copy>
I always get a null string transfered. Help much appreciated.
The to-spec <to variable="..." part="..." query="..."/> is not valid in BPEL 1.1 nor BPEL 2.0. The correct equivalent expression is: <to>$wsC_input.arg0/arg0/str</to> or <to variable="wsC_input" part="arg0"><query>/arg0/str</query></to>. Please make also sure that you initialize the variable before assigning values to nested structures.
Just found the mistake. You are right, we need to query in order to find the field like this:
<assign name="assign_2">
<copy>
<from variable="wsA_output" part="return"/>
<to>$wsC_input.message/arg0/str</to>
</copy>
</assign>
Also, we need to initialize the variable like this:
<assign name="assign_init">
<copy>
<from>
<literal><arg0><str xmlns="">nothing</str></arg0></literal>
</from>
<to variable="wsC_input" part="arg0"></to>
</copy>
</assign>
The xmlns="" is needed when the default namespace in your bpel is different that the namespace in the receiving web service.
I am just writing these down for future reference :)
Again, thanks for you your answer.
Some links that could also help other people:
http://ode.apache.org/faq.html
http://jee-bpel-soa.blogspot.com/2009/08/manipulating-ws-bpel-variables-and.html

Svc aspNetCompatibilityEnabled="true" is causing ServiceActivationException

I have a series of svc files within a web application, they all worked fine but I have a need to run with aspNetCompatibilityEnabled set to true and now I get the following exception
System.ServiceModel.ServiceActivationException: The requested service, '...' could not be activated. See the server's diagnostic trace logs for more information.
Where are these trace logs that it talks about and what could be causing this?
Thanks
So when turning aspNetCompatibilityEnabled to true, you need to apply changes in a couple of places. Firstly, i'm guessing you've done it in your web.config file. Secondly, you'll need to apply changes to services by decorating the service classes with AspNetCompatibilityRequirements attributes:
C#
[AspNetCompatibilityRequirements(
RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MySampleService
{
}
VB
<Activation.AspNetCompatibilityRequirements( _
RequirementsMode:=Activation.AspNetCompatibilityRequirementsMode.Allowed)> _
public class MySampleService
End Class
You can, if all services allow it, decorate a base service class with this attribute so it's inherited by all services by default.
You could activate extensive logging information by adding the following to your web.config:
<system.diagnostics>
<trace autoflush="true">
<listeners>
</listeners>
</trace>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "WcfDetailTrace.txt" />
</listeners>
</source>
</sources>
</system.diagnostics>
Then you could use SvcTraceViewer.exe to view the log file