1

我正在开发一个调用工作流服务的 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 文件中,接收活动采用一个字符串参数,而 sendreplytoreceive 活动提供 2 个参数作为输出。运行此代码时出现以下错误:

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 
4

1 回答 1

0

首先,在服务端打开 IncludeExceptionDetailsInFaults。您将能够从http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicedebugbehavior.includeexceptiondetailinfaults.aspx获得更多信息。

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

 <serviceDebug includeExceptionDetailInFaults="true" />

Eidt:所以接下来要尝试的是使用内置的错误处理来查看您是否可以看到服务端发生了什么。阅读这篇MSDN 文章。您需要添加以下内容:

<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 日志文件,您可以(希望)在其中看到与您的请求相关的错误。

于 2012-04-09T12:18:01.633 回答