无法从配置文件

时间:2016-08-28 17:09:02

标签: wcf wcf-binding workflow-activity

我的解决方案中有3个项目。第一个项目是asp.net mvc(作为客户端应用),另一个是WCF service application,最后一个是workflow activity library。我添加了WCF服务引用到工作流项目和工作流项目引用添加到asp.net mvc。当我在活动中使用wcf服务并从asp.net mvc启动工作流时,我收到此错误:

  

无法找到名称为BasicHttpBinding_IService的端点元素   并在ServiceModel客户端配置中签订IService   部分。这可能是因为找不到配置文件   您的应用程序,或者因为没有匹配此名称的端点元素   可以在客户端元素中找到。

这是我的工作流活动库app.config文件内容:

<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:30717/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="Service1.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

这是我的wcf项目web.config文件内容:

<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpBinding" scheme="http" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

这是我的asp.net mvc web.config文件内容:

<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:30717/Service1.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceTest.IService1"
          name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>
</configuration>

这是我在asp.net mvc控制器中运行工作流程的代码:

wf.Activity1 mm = new wf.Activity1();//wf is reference added from workflow project
mm.arg1 = "12".ToString() ;
IDictionary<string, object> res = WorkflowInvoker.Invoke(mm);
ViewBag.res = res["arg2"].ToString();

我用谷歌搜索了一天,不幸的是我没有得到结果。感谢您的导游。

修改 This是我提供更多帮助的项目。

2 个答案:

答案 0 :(得分:5)

从工作流配置文件中的合同和名称属性中删除“1”。

VS生成的BasicHttpBinding_IService类,在实例化时,会在config上查找匹配2个条件的某个合适端点:

  • 具有类的名称(BasicHttpBinding_IService,如果没有任何内容传递给构造函数)。命名空间也应该指示。在这里,终点的名称应该是.BasicHttpBinding_IService
  • 有一个由班级支持的合同。

为防止出现进一步的错误,您应该检查svc文件的名称,名称也以“1”结尾。绑定配置正常,因为绑定部分中存在完全相同的名称。

这是配置的简化版本:

<configuration>
<system.serviceModel>
    <client>
        <endpoint address="http://localhost:30717/Service.svc" binding="basicHttpBinding" contract="Service1.Service" name="<namespace>.BasicHttpBinding_IService" />
    </client>
</system.serviceModel>

您还可以使用Visual Studio WFC Service configuration tool(工具菜单上的快捷方式)编辑客户端和服务的配置文件。

答案 1 :(得分:2)

错误消息非常正确:您的WCF服务Web.config

中没有配置任何服务端点

添加服务节点并配置端点,如下所示:

 .... 
 <system.serviceModel>
    <services>
      <service name="MyService">
        <endpoint address="" binding="basicHttpBinding" contract="Service1.IService1" />
      </service>
    </services>
    <behaviors>
    ....
相关问题