none
Using WCF WF Service in a Web Project without creating a host

    Question

  • Hi

    I have created a WCF Workflow Service Application which contains multiple WCF Workflow Services in it. And some of these services contain multiple Send-Receive activities in a flowchart/sequence.

    In the same solution, I have created a Asp.Net Web project in which I have to use these WCF WF Services. In this Web Project, I added the Service Reference of the all the WCF Workflow Services that I have, but however when I try to invoke these WF services, it gives errors.

    I went thru various samples and in every sample there is ServiceHost created which makes available an endpoint, and consuming the service using this endpoint makes everything working. Now my questions are:

    1. Is there no way to make WF services work properly in a Web project without creating a WF Service Host??

    2. I am also having problems in persisting a workflow. As I mentioned earlier, I have some services which have multiple send-receive activities in it so I need to persist the workflow instance until the complete workflow is complete. Again, I was able to do this using the Service Host, but how to do it without using a service host?

     

    The problem is I have to host web application (and hence also the WF Services) on my Web hosting (GoDaddy) and on Azure Cloud and in both the cases I cannot create a separate Workflow Console Application that will work as host on a custom url.

     

    Please help me out. If you have any code samples, please provide them to me.

     

    Thanks


    Akshaya K Sharma
    Wednesday, September 22, 2010 5:54 PM

Answers

  • Okay this is what I did:

    Q1. "Is there no way to make WF services work properly in a Web project without creating a WF Service Host??"

    As I already mentioned here that I have to deploy my project on 2 servers - GoDaddy and Azure. On both of these servers, I dont have any control over the IIS at at all. All I know is .Net 4.0 is available...and I dont even know if they use IIS 7 or not. So, I had to be sure of the following in my project

    1. I have to make use of same hosting environment at a time i.e. either IIS 7 or the VS 2010 DevServer but not use them together.

    2. Since both in GoDaddy and Azure, I wont be aware of the physical paths...I cannot be using any physical paths directly.

    And as Patrick said above: "I believe that to add a service reference, the service has to be running so the dev environment can discover it- Is the service live when you're adding it?"

    When we add a service as a reference, Visual studio automatically makes it live.

    And then Juyu said above: "you can host WF Service in ASP.net Development Server (cassini). Right click on a xamlx file, and select 'View in Browser', it will host the WF Service project properly".

    This was also happening before too but it didnt solve my problem. Then I realized that maybe to host the workflow service in a separate project is not a good idea.

    Then, I started from scratch, here's what I did:

    1. I create a ASP.Net web project.

    2. Then instead of creating a new WF Service Project, I added the Workflow Service inside the Web project itself. The good thing about this I didnt had to worry about hosting 2 projects in GoDaddy or Azure.

    And then my luck shined. Now when I completed migrating all the components of my project all started to work. So, I thought the problem was when I was having 2 projects before - Web Project and the WF Service Project - when I ran the project and ran it with the single startup project configuration. So, when I changed the project execution configuration to multiple projects and marked both the projects to start - the same thing started to work over there. So, its only about the the service should be live when adding the service reference but also it should be alive when executing the code ;) But we do not need to worry about when keeping the WF service in the same project as the Web project since the WF service would be live automatically when you run the project.

    Now since, my WF service is running fine now, I come to my second question.

    Q2. "I am also having problems in persisting a workflow. As I mentioned earlier, I have some services which have multiple send-receive activities in it so I need to persist the workflow instance until the complete workflow is complete. Again, I was able to do this using the Service Host, but how to do it without using a service host?"

    Andrew: I already did the entry in the web.config file for SqlWorkflowInstanceStore.

    Then as per the url u gave, I followed the example mentioned here: http://msdn.microsoft.com/en-us/library/ff432975.aspx, but the problem was not solved. What I did was I ran my service using the WcfTestClient. I called the first method of the service, entered the initial details and I got a request id. Then I stopped the service, restarted my machine and the started the WcfTestClient again, but this time I continued with my second method call, with same request Id and the details but it didnt work out...it showed the instance missing, so what to do now?

     

    Thanks a lot all of you for your help.


    Akshaya K Sharma
    • Edited by Akshaya Sharma Saturday, September 25, 2010 6:44 AM Implement persistence solution but didnt work
    • Marked as answer by Akshaya Sharma Saturday, September 25, 2010 6:44 AM
    Saturday, September 25, 2010 6:28 AM

All replies

  • Their servers will need to be running .Net Framework 4.0 in order to host workflow services- you do need the framework (and thus a WorkflowServiceHost) to use the latest version of WCF workflow services.  If the server has AppFabric running on it, you can host the service in it directly, but it's hosting the service host anyway, so I'm guessing that's not a solution either.

     

     

    Wednesday, September 22, 2010 8:38 PM
    Moderator
  • Hi Patrick

    On server, .Net Framework 4.0 is available. In my question, what I meant was...in all the WF WCF samples, there are separate Workflow Console Projects which act as the service host i.e. they make available the WF service on the endpoint given in the console application. When I use the endpoint hosted via the console application all works fine.

    But when I consume the WF Service directly by Add Service Reference -> discover the services in my solution -> and adding the reference of the service I required. And then try to use the service thru this service reference object, the service doesnt work at all...it starts to throw errors like not found, etc.

    So, is there anything wrong in what I am doing? Or is there something that I missing?

    Thanks


    Akshaya K Sharma
    Thursday, September 23, 2010 4:07 AM
  • I believe that to add a service reference, the service has to be running so the dev environment can discover it- Is the service live when you're adding it?

     

     

    Thursday, September 23, 2010 6:41 PM
    Moderator
  • Hi, Akshaya

    ->"1. Is there no way to make WF services work properly in a Web project without creating a WF Service Host??"

    If your server installed IIS7 and .NET Framework 4. You can create a WF4 Service project in VS2010. and then create a ASP.NET application in IIS7. next set the physical path to the WF4 Service project. then any xamlx workflow will works, no need writing code, no need compile.

    ->"2. I am also having problems in persisting a workflow. As I mentioned earlier, I have some services which have multiple send-receive activities in it so I need to persist the workflow instance until the complete workflow is complete. Again, I was able to do this using the Service Host, but how to do it without using a service host?"

    Add the following configuration code to web.config file;
    <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
              <sqlWorkflowInstanceStore
                    connectionString="Data Source=.\sqlexpress;Initial Catalog=WF4PersistenceDB;Integrated Security=True"
                    instanceCompletionAction="DeleteAll"
                    instanceLockedExceptionAction="BasicRetry"
                    hostLockRenewalPeriod="00:00:05"              
                    />   
    ...
        
    Then, workflow service will be persisted when it is idle(delayed, or waiting client responce). of cause you have to setup the persistence store before adding these configuration code.

    For more about WF4 service, please check those documents:
    http://msdn.microsoft.com/en-us/library/dd456788.aspx

    Hope this helps.
    Regards
    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com
    Friday, September 24, 2010 8:26 AM
    Moderator
  • In addition to hosting in IIS, you can host WF Service in ASP.net Development Server (cassini). Right click on a xamlx file, and select 'View in Browser', it will host the WF Service project properly.

    Saturday, September 25, 2010 5:35 AM
    Moderator
  • Okay this is what I did:

    Q1. "Is there no way to make WF services work properly in a Web project without creating a WF Service Host??"

    As I already mentioned here that I have to deploy my project on 2 servers - GoDaddy and Azure. On both of these servers, I dont have any control over the IIS at at all. All I know is .Net 4.0 is available...and I dont even know if they use IIS 7 or not. So, I had to be sure of the following in my project

    1. I have to make use of same hosting environment at a time i.e. either IIS 7 or the VS 2010 DevServer but not use them together.

    2. Since both in GoDaddy and Azure, I wont be aware of the physical paths...I cannot be using any physical paths directly.

    And as Patrick said above: "I believe that to add a service reference, the service has to be running so the dev environment can discover it- Is the service live when you're adding it?"

    When we add a service as a reference, Visual studio automatically makes it live.

    And then Juyu said above: "you can host WF Service in ASP.net Development Server (cassini). Right click on a xamlx file, and select 'View in Browser', it will host the WF Service project properly".

    This was also happening before too but it didnt solve my problem. Then I realized that maybe to host the workflow service in a separate project is not a good idea.

    Then, I started from scratch, here's what I did:

    1. I create a ASP.Net web project.

    2. Then instead of creating a new WF Service Project, I added the Workflow Service inside the Web project itself. The good thing about this I didnt had to worry about hosting 2 projects in GoDaddy or Azure.

    And then my luck shined. Now when I completed migrating all the components of my project all started to work. So, I thought the problem was when I was having 2 projects before - Web Project and the WF Service Project - when I ran the project and ran it with the single startup project configuration. So, when I changed the project execution configuration to multiple projects and marked both the projects to start - the same thing started to work over there. So, its only about the the service should be live when adding the service reference but also it should be alive when executing the code ;) But we do not need to worry about when keeping the WF service in the same project as the Web project since the WF service would be live automatically when you run the project.

    Now since, my WF service is running fine now, I come to my second question.

    Q2. "I am also having problems in persisting a workflow. As I mentioned earlier, I have some services which have multiple send-receive activities in it so I need to persist the workflow instance until the complete workflow is complete. Again, I was able to do this using the Service Host, but how to do it without using a service host?"

    Andrew: I already did the entry in the web.config file for SqlWorkflowInstanceStore.

    Then as per the url u gave, I followed the example mentioned here: http://msdn.microsoft.com/en-us/library/ff432975.aspx, but the problem was not solved. What I did was I ran my service using the WcfTestClient. I called the first method of the service, entered the initial details and I got a request id. Then I stopped the service, restarted my machine and the started the WcfTestClient again, but this time I continued with my second method call, with same request Id and the details but it didnt work out...it showed the instance missing, so what to do now?

     

    Thanks a lot all of you for your help.


    Akshaya K Sharma
    • Edited by Akshaya Sharma Saturday, September 25, 2010 6:44 AM Implement persistence solution but didnt work
    • Marked as answer by Akshaya Sharma Saturday, September 25, 2010 6:44 AM
    Saturday, September 25, 2010 6:28 AM