Gewusst wie: Ändern der SOAP-Standardformatierung für einen ganzen Webdienst

Diese Prozedur beschreibt, wie die SOAP-Standardformatierung für einen ganzen Webdienst geändert wird.

So legen Sie den Formatierungsstil der Standardmethode für einen Webdienst fest

  • Wenden Sie entweder ein SoapRpcService-Attribut oder ein SoapDocumentService-Attribut auf die Klasse an, die den Webdienst implementiert.

    Im folgenden Codebeispiel wird der Formatierungsstil der Methode auf Document und die Standardparameterformatierung auf Literal festgelegt. Darüber hinaus wird angegeben, dass die Parameter innerhalb eines einzigen Elements gekapselt sein müssen.

    <%@ WebService Language="C#" Class="SoapDocumentServiceSample" %>
     using System.Web.Services;
     using System.Web.Services.Protocols;
     using System.Web.Services.Description;
    
    [SoapDocumentService(Use=SoapBindingUse.Literal,
                         ParameterStyle=SoapParameterStyle.Wrapped)]
    [WebService(Namespace="https://www.contoso.com")]
    public class SoapDocumentServiceSample  
    {
        [ WebMethod ]
        public string UseDefaultEncoding(Address MyAddress, 
                                         bool useZipPlus4) 
        {
         return "Use the default encodings for this Web service.";
        }
    }
    
    <%@ WebService Language="VB" Class="SoapDocumentServiceSample" %>
    Imports System.Web.Services
    Imports System.Xml.Serialization
    Imports System.Web.Services.Protocols
    Imports System.Web.Services.Description
    
    < SoapDocumentService(Use := SoapBindingUse.Literal, _
                          ParameterStyle := SoapParameterStyle.Wrapped)> _
    Public Class SoapDocumentServiceSample
      < WebMethod > _
      Public Function UseDefaultEncoding(MyAddress as Address, _
                                         useZipPlus4 As Boolean) As String 
         Return "Use the default formattings for this Web service."
      End Function
    End Class 
    

    Es folgt der XML-Teil der SOAP-Anforderung, der von der UseDefaultEncoding-Webdienstmethode erwartet wird.

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <UseDefaultEncoding xmlns="https://www.contoso.com">
          <MyAddress>
            <Street>string</Street>
            <City>string</City>
            <Zip>string</Zip>
          </MyAddress>
          <useZipPlus4>boolean</useZipPlus4>
        </UseDefaultEncoding>
      </soap:Body>
    </soap:Envelope>
    

Siehe auch

Referenz

SoapDocumentServiceAttribute
SoapRpcServiceAttribute

Weitere Ressourcen

Anpassen der Formatierung von SOAP-Nachrichten

Footer image

Copyright © 2007 by Microsoft Corporation. Alle Rechte vorbehalten.