Consume a WF hosted in IIS as a WCF service using ASP.NET 1.1 Client - wcf

As the title says, I would like to consume a WF workflow using a ASP.NET 1.1 client.
The workflow is hosted on IIS as a .svc service.
I have a .NET 3.5 winforms test client that uses wsHttpContextBinding.
Because I need to put a WorkflowID in Context to have my workflow rehydrated and continued, I use this piece of code:
var Svc = new MyClient.MyService();
var Ctx = new Dictionary<string, string>();
Ctx.Add("instanceId", workflowID.ToString());
var CtxMgr = Svc.InnerChannel.GetProperty<IContextManager>();
CtxMgr.SetContext(Ctx);
Svc.MyOperation();
It's working fine this way.
Unfortunately, my ASP.NET 1.1 legacy appliction need to consume this workflow. I have setup an additional endpoint that uses basicHttpContextBinding.
I have read the context has to be passed to a cookie, and I'm stuck here as I have no clue about how to do this in the caller code.
MyClient.MyService Svc= new MyClient.MyService();
// How to set the workflowID ?
Svc.MyOperation();
How can I set the context with a workflowID in the cookie ?

Apparently, there is no miracle nor solution. The workflowID has to be handled to the client side, which concerns me because the client is not aware about the server plumbing.

Related

WCF Web Service Call Using SOAP 1.1

I'm attempting to call a web service from a VB .NET 3.5 Win Forms application. I have been able to create a Service Reference but when I call the web service I receive the SOAP fault:
A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint.
The web service uses username and password authentication with a certificate. I also need to connect to different URLs depending on the environment (development or production). For these reasons I was attempting to use a WSHttpBinding created in code. However, it appears that type of binding assumes SOAP 1.2. I've been told by the author of the web service that they are unable to support SOAP 1.2.
Is there a way, either with the WSHttpBinding or a CustomBinding in code, to consume a web service that only supports SOAP 1.1 using a WCF Service Reference?
Dim binding As New System.ServiceModel.WSHttpBinding
binding.Security.Mode = ServiceModel.SecurityMode.Transport
binding.Security.Transport.ClientCredentialType = ServiceModel.HttpClientCredentialType.Basic
Dim service As New ServiceReference.ServiceClient(binding, New System.ServiceModel.EndpointAddress(baseUrl))
service.ClientCredentials.UserName.UserName = serviceUsername
service.ClientCredentials.UserName.Password = servicePassword
Any help is appreciated!

wcf wp7 service reference - session/coockie

i have and app that use a wcf service reference with the enableHttpCookieContainer="true" in the binding.
enableHttpCookieContainer is not really compatible in visual studio, i need every time that i need to update to delete it.
after few searchs i founded other methods to pass cookies in the wcf requests like this:
using (new System.ServiceModel.OperationContextScope(Channel))
{
System.ServiceModel.Channels.HttpRequestMessageProperty request = new System.ServiceModel.Channels.HttpRequestMessageProperty();
request.Headers["Cookie"] = CoockieContainer;
System.ServiceModel.OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = request;
}
but this don't work for me in wp7.
my question is, what is the officially, clean, compatbile way, to have a session in wcf when use from wp7 service reference? if wcf is hosted in a windows service instead a web site, there is not session, so i really think that the enableHttpCookieContainer is a fail and not clean way...

How to send WCF's ClientCredentials using Delphi XE

I've developd a WCF Service with a custom UserNamePasswordValidator with a basicHttpBinding using HTTPS. It works great with a .Net client, using ClientCredentials to send the username and password for authentication.
However, I need to call this from a Delphi XE client. How to I send the equivalent of .Net ClientCredentials using Delphi? Is that possible? If it is, how? If it is not, are there alternatives?
Tks
EDIT
Below is my client side code in .Net:
EndpointAddress oTransac = new EndpointAddress(GetAddress());
using (WebServiceClient oClient = new WebServiceClient ("httpbasic", oTransac))
{
oClient.ClientCredentials.UserName.UserName = "username";
oClient.ClientCredentials.UserName.Password = "password";
oClient.DoStuff();
}
EDIT
I've been doing some research, and I've been able to do authentication between Delphi and old asmx web services using SOAP Hearders. I found the article below. Will I be able to achieve the same behavior of the old [WebMethod] [System.Web.Services.Protocols.SoapHeader("SoapHeader")] using the article's technique?
http://weblogs.asp.net/paolopia/archive/2008/02/25/handling-custom-soap-headers-via-wcf-behaviors.aspx
EDIT BOUNTY
The get marked as the correct answer of the bounty, I would like to be able to call the web service from Delphi using WCF Service UserNamePasswordValidator on the server side.
First, basicHttpBinding is over HTTP (not HTTPS)
http://msdn.microsoft.com/en-us/library/ms731361.aspx
To consume a WFC service from Delphi is usually done by producing a WSDL from the service
How to create a single WSDL file from existing WCF service?
http://social.msdn.microsoft.com/Forums/en/wcf/thread/fc2c5074-1116-4f92-a972-01bb3a142535
WCF: how to generate a single WSDL document, without WSDL:import?
and generating a Delphi proxy class by importing that WSDL into your Delphi project.
>wsdlimport.exe service.wsdl
and then use the generated Delphi unit in your Delphi project
http://www.drbob42.com/examines/examinB9.htm
http://edn.embarcadero.com/article/36962
The parameters you send to service calls (username, password, ClientCredientials, etc) will be defined in the generated Delphi unit - should be no problem as long as you can connect to the service.
Some weeks ago I also had to connect to a WCF service. I ended up writing the client in .net and using UnmanagedExports
https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports
The dll can then be consumed in Delphi like a native dll

Programmatically creating a client proxy for a WIF-secured WCF Service

Here's what I've done so far:
1) Created an ASP.NET MVC relying party application and secured it with ADFS v2.0. This works.
2) Created a WCF Service using the Claims-Aware service template for an ASP.NET website. I've turned ASP.NET compatibility for the service ON because the service wouldn't activate otherwise. I've moved the interface for said service to a 'SharedContracts' assembly.
3) Set up the WCF service as a relying party using the "Add STS" reference, also pointing at my ADFS server.
4) Configured the ADFS server to include the WCF service as a relying party and issue it LDAP claims.
What I want to do now is talk to the service using ActAs. In other words, when someone hits HomeController.Index() from the ASP.NET MVC site with a token full of claims (remember the MVC site is a relying party), I want this method to programmatically create a client proxy and invoke the single service method I have on the WCF service (a method called "HelloClaim", which is nearly identical to the stock method that comes with the claims-aware service template).
Here's the code I've got so far:
[ValidateInput(false)]
public ActionResult Index()
{
SecurityToken callerToken = null;
IClaimsPrincipal claimsPrincipal = Thread.CurrentPrincipal as IClaimsPrincipal;
if (claimsPrincipal != null)
{
foreach (IClaimsIdentity claimsIdentity in claimsPrincipal.Identities)
{
if (claimsIdentity.BootstrapToken is SamlSecurityToken)
{
callerToken = claimsIdentity.BootstrapToken;
break;
}
}
string baseAddress = "http://khoffman2/SecureServices/Service.svc";
ChannelFactory<IHelloClaim> factory = new ChannelFactory<IHelloClaim>(new WebHttpBinding(), new EndpointAddress(baseAddress));
factory.ConfigureChannelFactory<IHelloClaim>();
IHelloClaim hello = factory.CreateChannelActingAs<IHelloClaim>(callerToken);
string result = hello.HelloClaim();
ViewData["Message"] = "Welcome to ASP.NET MVC!";
}
return View();
}
When I attempt to invoke the method, I get the following error message:
Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.
I'm pretty sure I'm just not doing enough to configure the binding and the endpoint programmatically. If any of you have done this before or you know how to do it, I would love to be able to get this working.
Bottom line is I'm just making use of the basic identity delegation scenario - the only difference is I'm not using generated client proxies.
Take a look at this guide over at TechNet as it has a walkthrough on how to setup the scenario you've described:
http://technet.microsoft.com/en-us/library/adfs2-identity-delegation-step-by-step-guide(WS.10).aspx
In their example, I believe they are using standard WebForms, but in the case of MVC you can put the ChannelFactory initialization within the Global.asax within the Application_Start.

Empty HttpContext when calling WCF webservice

I recently wrote a webservice to be used with Silverlight which uses the ASP.net membership and roles.
To validate the client in the service I look at the HTTPContext.Current.User (Which works when the service is called from Silverlight)
However, I've been trying to call the same service from an asp.net postback. But when I step-thru to the service the HTTPContext.Current has an emplty string for the username.
I'm guessing there is something that I'm not doing in the web.config file which is causing the httpContext to not be sent through the proxy to my service?
Any ideas would be appreciated. I need to be able to validate the client somehow using asp.net membership and roles and have it work from both an asp.net client and a silverlight client.
I have solved it!
Looks like by default the Silverlight application was sending all the browsers cookies to the service. One of these cookies is the ".ASPXAUTH" cookie to authenticate against the membership and roles.
The asp.net application however was not sending the cookies to the service. To send the authorisation cookie I used the following code before calling my webservice method.
using (OperationContextScope scope = new OperationContextScope(ws.InnerChannel))
{
HttpRequestMessageProperty httpRequest = new HttpRequestMessageProperty();
OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequest);
HttpCookieCollection cc = Page.Request.Cookies;
if (Request.Cookies[".ASPXAUTH"] != null)
{
HttpCookie aCookie = Request.Cookies[".ASPXAUTH"];
String authcookieValue = Server.HtmlEncode(aCookie.Value);
httpRequest.Headers.Add("Cookie: " + ".ASPXAUTH=" + authcookieValue);
}
// Webservice call goes here
}
Instead of HTTPContext try ServiceSecurityContext.Current.PrimaryIdentity
Not sure how it is working from Silverlight but not ASP.Net, but for starters here is a good blog post on how to setup WCF to work with ASP.Net membership providers. There are quite a few steps so this could be pretty easy to miss a setting.
Once you get that working correctly then I imagine both should work correctly.
I think it may be because my wcf service is in my silverlight.web project, and perhaps they are more friendly when it comes to sharing.
I may need to read up more on wcf and create a greater seperation of concerns by setting up a seperate webservice project?
Update:
Ok I've taken a look at the HTTP Post request using Fiddler
Looks like the Silverlight App is sending a 'State' with an authorization cookie and my asp.net app isn't.
Looks like I need to send the state + my authorization cookie when I call the service. I may need to formulate a new question soon...