开发者

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

开发者 https://www.devze.com 2023-03-17 12:14 出处:网络
When using ASP.NET Webservice it automatically adds the MethodNameResult and MethodaNameResponse. Is there a easy way to not inclu开发者_如何学Cde them, and can we do the same with the request?

When using ASP.NET Webservice it automatically adds the MethodNameResult and MethodaNameResponse.

Is there a easy way to not inclu开发者_如何学Cde them, and can we do the same with the request?

I.e., remove <tem:HelloWorld><tem:xml> from

<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 ??? 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

... to throw your own xml back to the client

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 ...

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.

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.

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 ...

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

...

Is this more helpful?

0

精彩评论

暂无评论...
验证码 换一张
取 消