相关疑难解决方法(0)

将MSMQ端到端跟踪与WCF跟踪和应用程序级别日志记录相关联

背景:

我正在解决WCF通过事务MSMQ(带netMsmqBinding)发送的消息似乎消失的问题.使用WCF的代码是在第三方程序集中,我无法更改.我几乎找不到问题的线索,但计划启用各种跟踪功能,以便确定问题所依赖的位置.

语境:

  1. 我启用了MSMQ 端到端跟踪.它为每个发送的消息记录两个事件.

    • 将消息写入传出队列时的一个事件.该消息包含MSMQ消息id(由guid和整数组成,即7B476ADF-DEFD-49F2-AF5A-0CF27C5152C0\6481271).
    • 通过网络发送该消息的另一个事件.
  2. 我启用了详细的WCF跟踪.

  3. 我还有应用程序级别的日志记录,它记录由应用程序代码定义的消息ID(让我们称之为"应用程序消息ID").

  4. 我已经在发送的MSMQ消息上启用了正面和负面源日记功能.

  5. 我已在接收队列上启用了日记功能.

问题:

当消息丢失时,我知道丢失消息的应用程序ID(它由发送方记录).我现在想看一下End-to-End跟踪,看看消息是否写入了传出队列.

如何将端到端跟踪中的事件与应用程序级别日志和WCF跟踪相关联?

思路:

  • 在System.Messaging中使用托管MSMQ API发送MSMQ消息时,消息的MSMQ ID在发送消息后可用.但是,当WCF执行发送操作时,我还没有找到记录此方法的方法.WCF跟踪记录了一个MSMQMessageId guid,但令人惊讶的是,这个值并不是我猜想的实际MSMQ id.是否可以访问实际的MSMQ消息ID并记录它?

  • 在应用程序日志中记录本机线程ID以及应用程序级别ID和时间戳.MSMQ将本机线程ID记录到端到端跟踪中,因此实际上这可能足以进行关联.如果我找不到更优雅的解决方案,这是我的计划B.

wcf msmq

37
推荐指数
1
解决办法
1182
查看次数

如何将HTTP标头添加到SOAP客户端

如果有可能将HTTP标头添加到soap客户端Web服务调用,有人可以回答我.浏览互联网后,我发现的唯一的薄是如何添加SOAP标头.

代码如下所示:

var client =new MyServiceSoapClient();
//client.AddHttpHeader("myCustomHeader","myValue");//There's no such method, it's just for clearness
var res = await client.MyMethod();
Run Code Online (Sandbox Code Playgroud)

更新:

The request should look like this
POST https://service.com/Service.asmx HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://www.host.com/schemas/Authentication.xsd/Action"
Content-Length: 351
MyHeader: "myValue"
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header/>
  <s:Body>
    <myBody>BodyGoesHere</myBody>
  </s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)

信封中的标题属性应为空

c# soap-client windows-8

12
推荐指数
2
解决办法
2万
查看次数

在现有WCF SOAP服务中添加Http Header无效

我想要一个HTTP头到我的WCF SOAP服务.我的最终目标是通过此HTTP标头发送API密钥.

以下是我的代码:

[ServiceBehavior(Namespace = "http://****.com/**/1.1")]
public class MyWcfSvc : IMyVerify
{
    const int MaxResponseSize = 0xffff; // 64K max size - Normally it will be MUCH smaller than this

    private static readonly NLogLogger Logger;

    static MyWcfSvc()
    {
        Logger = new NLogLogger();
        // Add an HTTP Header to an outgoing request 
        HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
        requestMessage.Headers["User-Auth"] = "MyHttpHeaderValue";
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
    }
}
Run Code Online (Sandbox Code Playgroud)

我没有User-Auth在HTTP请求标头下看到标头.

我也尝试过另一种方式.

public AnalyzeResponse Analyze(AnalyzeRequest analyzeRequest)
    {
        HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
        requestMessage.Headers["User-Auth"] = …
Run Code Online (Sandbox Code Playgroud)

c# wcf soap web-services api-key

8
推荐指数
2
解决办法
2452
查看次数

WCF和身份验证

每次请求发送到WCF并在服务器上检查该值并决定是否发出请求时,我需要从客户端传递一个值,任何人都可以写一个例子吗?我不知道这是怎么实现的

case:我根据客户端的硬件生成一个密钥,我希望将该密钥发送到服务器,每次请求检查服务器db中是否接受密钥,然后决定是否处理请求.

提前致谢.

c# wcf web-services

6
推荐指数
1
解决办法
3538
查看次数

如何将 SOAP 标头附加到我的 C# 客户端?

我已将 Web 服务设置为接收"TestHeader"带有 param名称的 soap 标头"Name"

如何在我的客户端中创建一个 soap 标头并将其发送到服务?

到目前为止,我已经在我的客户端中创建了它。

public class TestHeader : SoapHeader
{
    public String Name;
}
Run Code Online (Sandbox Code Playgroud)

初始化我的服务,

    Test.TestServicesClient SOAP = new Test.TestServicesClient();
Run Code Online (Sandbox Code Playgroud)

初始化我的标题。

  TestHeader header = new TestHeader();
Run Code Online (Sandbox Code Playgroud)

在标题中设置变量

header.Name = "BoB";
Run Code Online (Sandbox Code Playgroud)

怎么办?我试过遵循 MSDN 和其他教程,但一无所获。

测试服务.cs

using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;

namespace Test
{

    // Define a SOAP …
Run Code Online (Sandbox Code Playgroud)

c# soap web-services soapheader

5
推荐指数
2
解决办法
5万
查看次数

从请求上下文添加和检索数据

我正在尝试将api密钥附加到OperationContext传出消息头,如下所示:

    public static void AddApikeyToHeader(string apikey, IContextChannel channel, string address)
    {
        using (OperationContextScope scope = new OperationContextScope(channel))
        {
            MessageHeader header = MessageHeader.CreateHeader("apikey", address, apikey);
            OperationContext.Current.OutgoingMessageHeaders.Add(header);

        }
    }
Run Code Online (Sandbox Code Playgroud)

但后来我不知道如何检索服务器端的标头.我正在使用服务授权管理器,我得到当前的操作上下文并尝试检索这样的标题:

    public string GetApiKey(OperationContext operationContext)
    {
        var request = operationContext.RequestContext.RequestMessage;

        var prop = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];

        return prop.Headers["apikey"];
    }
Run Code Online (Sandbox Code Playgroud)

但那里没有附加的apikey标题.另外,在我检查operationContext的时候调试我似乎无法在任何地方看到我的apikey头.谁能看到我哪里出错了?

c# wcf asp.net-mvc-3

5
推荐指数
1
解决办法
1万
查看次数

使用CustomBinding进行抢先认证?

我正在使用WCF针对客户的SOAP服务编写客户端.

我们已经进行了多次复飞,试图让身份验证正常运行.我最终使用了Custom Binding,因为Web上的一些随机人员说BasicHttpBinding不支持必要的安全选项,而且WsHttpBinding不支持SOAP 1.1,这就是他们正在使用的.

那么,我有什么:

var message = this.constructMessagecollection);

if (message != null)
{
    var ea = new EndpointAddress(this.webServiceUrl);

    var binding = new CustomBinding();
    binding.Elements.Add(new TextMessageEncodingBindingElement(
            MessageVersion.Soap11, Encoding.UTF8));
    binding.Elements.Add(new HttpsTransportBindingElement { AuthenticationScheme = System.Net.AuthenticationSchemes.Basic });

    using (var client = new CustomersWebserviceClient(binding, ea))
    {
        if (!String.IsNullOrWhiteSpace(this.webServiceUsername) && !String.IsNullOrWhiteSpace(this.webServicePassword))
        {
            var credentials = client.ClientCredentials.UserName;
            credentials.UserName = this.webServiceUsername;
            credentials.Password = this.webServicePassword;
        }

        var result = client.ReceiveMessage(message);
        log.writeLine(String.Format("Call to client.ReceiveMessage() returned {0}", result));
    }

    return true;
}
Run Code Online (Sandbox Code Playgroud)

现在,我被问到是否可以将我的客户端配置为执行抢占式身份验证.我做了一些网页浏览,但没有找到太多.而且我不知道如何将我发现的很少的东西整合到我当前的代码中.

wcf soap basic-authentication

1
推荐指数
1
解决办法
2737
查看次数