gpt4 book ai didi

c# - 有没有办法从 ASP.NET WebMethod 中获取原始 SOAP 请求?

转载 作者:太空狗 更新时间:2023-10-29 17:31:50 25 4
gpt4 key购买 nike

例子:

public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public int Add(int x, int y)
{
string request = getRawSOAPRequest();//How could you implement this part?
//.. do something with complete soap request

int sum = x + y;
return sum;
}
}

最佳答案

SoapExtensions 的替代方法是实现 IHttpModule 并在输入流传入时获取它。

public class LogModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += this.OnBegin;
}

private void OnBegin(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext context = app.Context;

byte[] buffer = new byte[context.Request.InputStream.Length];
context.Request.InputStream.Read(buffer, 0, buffer.Length);
context.Request.InputStream.Position = 0;

string soapMessage = Encoding.ASCII.GetString(buffer);

// Do something with soapMessage
}

public void Dispose()
{
throw new NotImplementedException();
}
}

关于c# - 有没有办法从 ASP.NET WebMethod 中获取原始 SOAP 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2587952/

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