调用工作流服务而不将其作为服务添加到解决方案中

时间:2012-04-09 12:11:22

标签: c# workflow-foundation workflow-foundation-4 workflow-activity workflowservice

我正在开发一个调用工作流服务的asp .net网络项目。我想调用该服务而不将其作为服务添加到解决方案中。我使用以下代码

XNamespace ns = "http://schemas.microsoft.com/2003/10/Serialization/";

var factory = new ChannelFactory<IGenericService>(new BasicHttpBinding(), new EndpointAddress("http://localhost:2757/BPMNSimple.xamlx"));

var proxy = factory.CreateChannel();

var request = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/IService/TestSimple", new XElement(ns + "string", "45"));

var response = proxy.GetData(request); 

var xml = (XElement)XElement.ReadFrom(response.GetReaderAtBodyContents());
var message = xml.Value;
lblMessage.Text = message.ToString();

在xamlx文件中,receive活动接受一个参数,该参数是一个字符串,sendreplytoreceive活动将两个参数作为输出。运行此代码时出现以下错误:

System.ServiceModel.CommunicationException: The server did not provide a meaningful reply;   
this might be caused by a contract mismatch, a premature session shutdown or an internal server error. Server stack trace: 
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: 
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
at _Default.IGenericService.GetData(Message request) 
at _Default.Page_Load(Object sender, EventArgs e) in c:\Users\marios\Documents\Visual Studio 2010\WebSites\WebSite2\Default.aspx.cs:line 63 

1 个答案:

答案 0 :(得分:0)

在第一个实例中,在服务端打开IncludeExceptionDetailsInFaults。您将能够从http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicedebugbehavior.includeexceptiondetailinfaults.aspx获取更多信息。

您需要在服务web.config中添加以下内容:

 <serviceDebug includeExceptionDetailInFaults="true" />

Eidt: 所以接下来要尝试的是使用内置的错误处理来查看你是否能看到正在发生的事情。阅读此MSDN article。你需要添加像:

这样的东西
<configuration>
 <system.diagnostics>
  <sources>
        <source name="System.ServiceModel" 
                switchValue="Information, ActivityTracing"
                propagateActivity="true">
        <listeners>
           <add name="traceListener" 
               type="System.Diagnostics.XmlWriterTraceListener" 
               initializeData= "c:\log\Traces.svclog" />
        </listeners>
     </source>
  </sources>
</system.diagnostics>

这将创建一个WCF日志文件,您可以(希望)看到与您的请求相关的错误。