gpt4 book ai didi

wcf - 使用 WireShark 检查本地主机上的 WCF TCP 服务器和客户端流量

转载 作者:可可西里 更新时间:2023-11-01 02:46:21 25 4
gpt4 key购买 nike

我使用 WCF 在 Visual Studio 中创建了一个简单的 TCP 客户端和 TCP 服务器。我在服务器上有一个简单的操作,它接收一个整数,递增它并发回它。它按预期工作。

我想使用 Wireshark 来监控在本地主机上运行的客户端和服务器之间的流量。显然,这对于 Windows 上的 Wireshark 标准安装是不可能的,因为它无法监控环回适配器。有一个名为 Npcap 的库旨在解决这个问题,所以我安装了这个:

Npcap on GitHub

当我运行 Wireshark 并选择捕获

Npcap Loopback Adapter

我没有看到任何 TCP 流量(只有一些 UDP 和 DHCP)。我想知道我希望看到什么?

服务器的 C# 代码在这里(我以编程方式创建它以便您可以看到所有详细信息,App.Config 中没有配置任何内容)

using System;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace TcpServer
{
// Defining the service
[ServiceContract]
public interface ITcpService
{
[OperationContract]
int GetNumber(int num);
}

// Implementing the service
public class TcpService : ITcpService
{
public int GetNumber(int num)
{
return num + 1;
}
}

class TcpServerConsole
{
static void Main(string[] args)
{
ServiceHost host;

// Attempt to open the service
try
{
// Create the service host with a Uri address and service description
host = new ServiceHost(typeof(TcpService), new Uri("net.tcp://127.0.0.1:9000/MyService"));

// Create the metadata that describes our service, add it to the service host
var metadataBehavior = new ServiceMetadataBehavior() { HttpGetEnabled = false };
host.Description.Behaviors.Add(metadataBehavior);

// Add a tcp endpoint for our service, using tcp
host.AddServiceEndpoint(typeof(ITcpService), new NetTcpBinding(), "");

// Add the meta data service endpoint for describing the service
var mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
host.AddServiceEndpoint(typeof(IMetadataExchange), mexBinding, "net.tcp://127.0.0.1:9000/MyService/mex");

// Open our service
host.Open();
}
catch (Exception e)
{
// Catch any problem with creating the service and report
Console.WriteLine("Failed to open the server: {0}", e.Message);
Console.WriteLine("Press [Return] to close");
Console.ReadKey(true);
return;
}

// Halt the program to keep the service open
Console.WriteLine("Press [Return] to close server");
Console.ReadKey(true);
host.Close();
}
}
}

最佳答案

我是 Npcap 的作者。首先感谢举报!

首先,我想提一下,获得有关 Npcap 帮助的最佳方式是使用邮件列表:dev@nmap.org 或在 https://github.com/nmap/nmap/issues 发一个问题。 .我每天检查那些地方。我主要使用 Stackoverflow 来提问,但不怎么搜索和回答有关 Npcap 的问题。

我不是 C# 专家。我在我的 VS2015 中创建了一个 WCF 服务应用程序 项目。将您的代码复制到我的 Service1.svc.cs。将其构建到 WcfService1.dll 中。但是不知道怎么用?

您介意提供所有服务器和客户端代码(包括解决方案文件)吗?所以我可以只用它们来测试 Npcap(不需要掌握有关 C# 和 WCF 的知识)。您可以压缩代码并将邮件中的 zip 附加到 dev@nmap.org。我会回复它。谢谢!

关于wcf - 使用 WireShark 检查本地主机上的 WCF TCP 服务器和客户端流量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35633034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com