Procedura: modificare la formattazione SOAP predefinita per un intero servizio Web
Questo argomento è specifico di una tecnologia legacy. Servizi Web XML e client di servizi Web XML devono essere creati attualmente tramite Windows Communication Foundation.
Nella seguente procedura viene illustrato come modificare la formattazione SOAP predefinita per un intero servizio Web.
Per impostare il metodo di formattazione predefinito per un servizio Web
Applicare un attributo SoapRpcService o un attributo SoapDocumentService alla classe che implementa il servizio Web.
Nell'esempio di codice seguente viene impostato lo stile del metodo di formattazione su Document e la formattazione del parametro predefinito su Literal, e viene specificato che i parametri devono essere incapsulati all'interno di un singolo elemento.
<%@ 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
Segue la parte XML della richiesta SOAP attesa dal metodo del servizio Web
UseDefaultEncoding
.<?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>
Vedere anche
Riferimento
SoapDocumentServiceAttribute
SoapRpcServiceAttribute