Freigeben über


Extending the WF publish as Web Service, or get rid of tempuri.org

If you have been using Windows Workflow Foundation to build web service business logic, you may be using the publish-as-web-service tool that is part of the Visual Studio extensions for Windows Workflow Foundation. How it works is if you have a workflow model defined in a Visual Studio project you can right click on the project and choose "Publish as Web Service" from the menu. The tool will add a new project to your solution which is a web service. This new web service will execute the workflow. Your workflow model must have at least one WebServiceInput activity in it to do this.

The thing that many people have been finding is that it uses the default namespace of TEMPURI.ORG and it's not configurable. Well here's how you can change the namespace with a minimum of fuss. We're planning a KB article with a more official description of this.

1) First the web service is generated code which is compiled and you are left with the DLL only. The source is deleted by default. You want to change that. There's a registry key that you can set to keep the source for the web service. Usual disclaimers apply about changing the registry on your machine. Here's the key to set:

  • HKLM/SOFTWARE/Microsoft/NET Framework Setup/NDP/v3.0/Setup/Windows Workflow Foundation
  • Create a new REG_DWORD key called KeepTempFiles and set its value to 1.

2) Next go ahead and publish your web service normally as described above. This will create the source and compile it, but it will not be deleted. Right click on your web service project and choose ASP.NET Folder -> App_Code. Now you need to go and fetch the generated source from your Temp directory. My temp directory on Windows Vista is at C:\Users\pandrew\AppData\Local\Temp. Find the recently generated .CS file there and copy it. My test one here was called 077px_9s.cs. Put this file into the App_Code folder using explorer. Now edit the .ASMX file in your project and add the CodeBehind="~/Filea.cs". See I renamed the file from 077px_9s.cs to Filea.cs. My test WorkflowLibrary1.Workflow1_WebService.asmx file now looks like this:

<%@ WebService CodeBehind="~/Filea.cs" Class="WorkflowLibrary1.MyClass" %>

3) The final step is to open your newly added code behind file and add the new namespace into the file. Just add the WebService attribute to the class and specify the namespace in that attribute, something like this:

[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1, EmitConformanceClaims=true)]

[WebService(Namespace="https://www.contoso.com")]

public class MyClass : WorkflowWebService

{

Once you've done that you can recompile the project and you should have a web service that is implemented by a workflow model and your chosen namespace.

PS: This is my first blog entry written in Word 2007.

Comments

  • Anonymous
    October 25, 2006
    Useful, but horrible :-) I can't see fishing around in the Temp folder as a part of anyone's development process for anything more than a one-off - are there plans to add a namespace override option for RTM?

  • Anonymous
    October 25, 2006
    The comment has been removed

  • Anonymous
    October 25, 2006
    Understood, I wasn't making a eature request at this late stage. I was just hoping someone might have thought of it in time.

  • Anonymous
    October 27, 2006
    Please create a VS.NET macro or shortcut that does this.  This is horrible; can't imagine doing this each time my WF project WS receive changes... Thanks for the article, at least its possible now. Best regards, Christof

  • Anonymous
    October 29, 2006
    By default the web service wrapper generated around a workflow use the "tempuri.org" namespace. Not very

  • Anonymous
    October 30, 2006
    Some of my collegaues are working on a much better solution than this work around. Hope to see this posted shortly. Cheers, Paul