Far*_*hid 9 wcf workflow-activity wcf-binding
我的解决方案中有3个项目.第一个项目是asp.net mvc(作为客户端应用程序),另一个是WCF service application最后一个项目workflow activity library.我添加了WCF服务引用到工作流项目和工作流项目引用添加到asp.net mvc.当我在活动中使用wcf服务并从asp.net mvc启动工作流时,我收到此错误:
无法在ServiceModel客户端配置部分中找到名称为BasicHttpBinding_IService和合同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>
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我在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();
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了一天,不幸的是我没有得到结果.谢谢你的导游.
编辑: 这是我的项目以获得更多帮助.
从工作流配置文件中的合同和名称属性中删除"1".
VS生成的BasicHttpBinding_IService类在实例化时,会在配置中查找匹配2个条件的某个合适端点:
为了防止进一步的错误,您应该检查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>
Run Code Online (Sandbox Code Playgroud)
您还可以使用Visual Studio WFC Service configuration tool(工具菜单上的快捷方式)编辑客户端和服务的配置文件.
错误消息非常正确:您没有在 WCF 服务中配置任何服务端点Web.config
添加服务节点并配置端点,如下所示:
....
<system.serviceModel>
<services>
<service name="MyService">
<endpoint address="" binding="basicHttpBinding" contract="Service1.IService1" />
</service>
</services>
<behaviors>
....
Run Code Online (Sandbox Code Playgroud)