asmx中的SOAP请求和响应 [英] SOAP Request and Response in asmx

查看:97
本文介绍了asmx中的SOAP请求和响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在asmx Web方法中捕获SOAP消息?

例如,我们需要为客户端创建一个发送SOAP消息以检查偶数或奇数的方法,

How can we capture a SOAP massage in asmx web method?

For example we need to create a method for client is sending a SOAP massage for checking a number even or odd,

<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<sone:check xmlns:sone="http://www.xxxx.com/webservices/schemas"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sone:Number xsi:type="xsd:string">4</sone:partnerLogin>
</sone:check>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>



我们需要在下面的SOAP本身中对它们进行响应.



and we need to response them in SOAP itself iike below.

<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<sone:CheckResult xmlns:sone="http://www.xxxxxxxxx.com/webservices/schemas"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sone:Result xsi:type="xsd:string">Number is even</sone:partnerLogin>
</sone:CheckResult >
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>



使用ASP.net和C#.

感谢您对Advanced



using ASP.net and C#.

Thanks for help in advanced

推荐答案

的帮助.要捕获SOAP请求/响应,您可以使用以下代码实现IHttpModule并在输入流进入时抓取它:

To capture SOAP request/response, you can implement IHttpModule and grab the input stream as it''s coming in using the below code:

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();
    }
}


这篇关于asmx中的SOAP请求和响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆