简体   繁体   English

如何获得调用Web服务之前请求

[英]How to get request before call to webservice

Problem: As part of a debugging a problem regarding some validation issues I would like to read the XML request of an WCF webservice. 问题:作为一个调试的一部分,我想读一个WCF web服务的XML请求,对于一些验证问题的一个问题。

Apparently, this is more difficult than it appears and any help in this regard would be much appreciated. 显然,这比看起来要困难得多,在这方面的任何帮助将不胜感激。 Below are what I've tried already. 以下是我已经尝试过的内容。 Much like the answer to a similar question here on StackOverflow ( link ). 就像在StackOverflow( link )上对类似问题的答案一样。

My solution: I've created the client setting the endpoint given by the provider of the webservice. 我的解决方案:我已经创建了客户端,该客户端设置了Web服务提供商提供的端点。 I've added my client credentials as an endpoint behavior. 我已添加我的客户端凭据作为端点行为。 Right before I make the call to service I add another endpoint behavior to write the request and response as XML-files. 在进行服务调用之前,我添加了另一个端点行为,以XML文件形式写入请求和响应。 Alas, to no avail. las,无济于事。

The simple call to the webservice: 对Web服务的简单调用:

public SaveAvailabilityAssessmentResponseType SaveAvailabilityAssessment(SaveAvailabilityAssessmentRequestType request)
{
   Client.Endpoint.Behaviors.Add(new CustomEndpointBehavior());

   return Client.SaveAvailabilityAssessment(_ocesCertHeader, _activeOrganisationHeader, request);
}

And here are the CustomEndpointBehavior class (simplified a bit): 这是CustomEndpointBehavior类(简化了一点):

public class CustomEndpointBehavior : IEndpointBehavior
{
    public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
    {
        clientRuntime.MessageInspectors.Add(new MessageExpector());
    }
}

And here's the MessageExpector class: 这是MessageExpector类:

internal class MessageExpector : IClientMessageInspector
{
    public void AfterReceiveReply(ref Message reply, object correlationState)
    {
        using (var sw = new StreamWriter(@"C:\temp\response.xml"))
        {
            sw.WriteLine(reply);
        }
    }

    public object BeforeSendRequest(ref Message request, IClientChannel channel)
    {
        using (var sw = new StreamWriter(@"C:\temp\request.xml"))
        {
            sw.WriteLine(request);
        }
        return new object();
    }
}

Can anyone tell me what I'm missing? 谁能告诉我我所缺少的吗?

Edit: Further debugging has showed, that the code in the CustomEndpointBehavior hasn't been activated. 编辑:进一步的调试表明,CustomEndpointBehavior中的代码尚未激活。 It is as if the customendpoint hasn't been added to the client's endpoint behaviors. 好像尚未将customendpoint添加到客户端的端点行为中。 But how can that be? 但是那怎么可能呢?

You can configure message logging without modifying your code. 您可以配置消息日志记录而无需修改代码。 Here's a link to documentation . 这是文档的链接 You can use SvcTraceViewer.exe for viewing this logs 您可以使用SvcTraceViewer.exe查看此日志

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM