【问题标题】:Could not find endpoint element with Name and Contract from config file无法从配置文件中找到具有名称和合同的端点元素
【发布时间】:2017-01-04 17:58:52
【问题描述】:

我的解决方案中有 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 是我寻求更多帮助的项目。

【问题讨论】:

    标签: wcf wcf-binding workflow-activity


    【解决方案1】:

    错误消息非常正确:您没有在 WCF 服务中配置任何服务端点Web.config

    添加一个服务节点并像这样配置端点:

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

    【讨论】:

    • 我在我的 wcf 配置文件中使用了你建议的配置,但我得到了那个错误。
    【解决方案2】:

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

    VS生成的BasicHttpBinding_IService类,当实例化时,它会在配置中查找一些符合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(工具菜单上的快捷方式)来编辑客户端和服务的配置文件。

    【讨论】:

    • 我将 Dowork 活动添加到 wf 活动文件(Dowork 是我在 wcf 服务应用程序中的操作名称),当我逐步运行我的项目时(f11)​​我在 Dowork 活动中的发送/接收序列中出现错误.
    • 我认为你需要解决这个问题。使用一个简单的服务和一个客户端进行测试将有助于了解背后的原因
    • 我忘了把类的命名空间作为后缀,答案已更新以反映这一点。
    • 你的 是什么意思
    • 替换为类命名空间
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    相关资源
    最近更新 更多