简体   繁体   English

如何从请求响应中删除 SOAP 信封方法名称?

[英]How do I remove SOAP envelope method names from request response?

When using ASP.NET Webservice it automatically adds the MethodNameResult and MethodaNameResponse .使用 ASP.NET Webservice 时,它会自动添加MethodNameResultMethodaNameResponse

Is there a easy way to not include them, and can we do the same with the request?有没有一种简单的方法可以不包括它们,我们可以对请求做同样的事情吗?

Ie, remove <tem:HelloWorld><tem:xml> from即,从<tem:HelloWorld><tem:xml>中删除

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:HelloWorld>
         <tem:xml>

Here is the response sample这是响应示例

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <HelloWorldResponse xmlns="http://tempuri.org/">
         <HelloWorldResult>
         </HelloWorldResult>
      </HelloWorldResponse>
   </soap:Body>
</soap:Envelope>

um... you could manually handle the response and stream back your own xml string but why would you do this???嗯...您可以手动处理响应,然后 stream 返回您自己的 xml 字符串,但是您为什么要这样做? this would break any client applications built against it.这将破坏针对它构建的任何客户端应用程序。

EDIT: (Call it elaboration):编辑:(称之为阐述):

Essentially what you need to do is create your own "soap extention"...本质上,您需要做的是创建自己的“肥皂扩展”......

public class MySOAPExtension : SoapExtension
{

     Stream oldStream;
     Stream newStream;

     // Save the Stream representing the SOAP request or SOAP response into
     // a local memory buffer.
     public override Stream ChainStream( Stream stream )
     {
            oldStream = stream;
            newStream = new MemoryStream();
            return newStream;
     }

    public override void ProcessMessage(SoapMessage message)
    {
       switch (message.Stage)
        {
            case SoapMessageStage.BeforeDeserialize:
                // before the XML deserialized into object.
                break;
            case SoapMessageStage.AfterDeserialize:
                break;        
            case SoapMessageStage.BeforeSerialize:
                break;
            case SoapMessageStage.AfterSerialize:
                break;            
            default:
                throw new Exception("Invalid stage...");
        }       
    }
}

From here you can pick which part of the process you are interested in and if need be combine this with the information found here...从这里您可以选择您感兴趣的流程的哪一部分,如果需要,可以将其与此处找到的信息相结合...

http://msdn.microsoft.com/en-us/library/ms525585%28v=vs.90%29.aspx http://msdn.microsoft.com/en-us/library/ms525585%28v=vs.90%29.aspx

... to throw your own xml back to the client ...将自己的 xml 扔回客户端

It's not easy, and does require quite a bit of knowledge of the service lifecycle but at least this follows the typical asp.net model for servicing requests...这并不容易,并且确实需要对服务生命周期有相当多的了解,但至少这遵循典型的 asp.net model 服务请求......

http://msdn.microsoft.com/en-us/library/ms178473.aspx http://msdn.microsoft.com/en-us/library/ms178473.aspx

I would think you're only interested in handling "SoapMessageStage.AfterSerialize" from the above switch block to manipulate the soap envelope.我认为您只对处理上述开关块中的“SoapMessageStage.AfterSerialize”来操作 soap 信封感兴趣。

Post note:发帖说明:

based on your further comment of manipulating the request soap packet, that would have to be done by the calling client as the client builds a soap packet which the server uses as an instruction, manipulating the request envelope may however affect how it's handled or in fact break the servers handling of the soap packet.根据您对操作请求 soap 数据包的进一步评论,这将必须由调用客户端完成,因为客户端构建了服务器用作指令的 soap 数据包,但操作请求信封可能会影响它的处理方式或实际上中断对 soap 数据包的服务器处理。

With all this in mind you may find that it's more suitable to simply implement a custom httphandler instead as that would accept anything and potentially return anything, using web services imposes some basic formatting rules implied by the soap standard http handlers do not...考虑到这一切,您可能会发现简单地实现自定义 httphandler 更合适,因为它可以接受任何内容并可能返回任何内容,使用 web 服务会强制执行 soap 标准 Z80791B3AE7002FACB88888 处理程序68766 所隐含的一些基本格式规则...

http://support.microsoft.com/kb/308001 http://support.microsoft.com/kb/308001

... ...

Is this more helpful?这更有帮助吗?

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

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