我正在处理一个调用工作流服务的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:UsersmariosDocumentsVisual Studio 2010WebSitesWebSite2Default.aspx.cs:line 63
首先,在服务端打开 IncludeExceptionDetailsInFaults。您将能够从 http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicedebugbehavior.includeexceptiondetailinfaults.aspx 获得更多信息。
您需要将类似以下内容的内容添加到您的服务 web.config:
<serviceDebug includeExceptionDetailInFaults="true" />
开斋节:因此,接下来要尝试的是使用内置的错误处理,看看您是否可以看到服务端发生了什么。请阅读此 MSDN 文章。您需要添加类似以下内容的内容:
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:logTraces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
这将创建一个 WCF 日志文件,您可以在其中(希望)看到与您的请求相关的错误。