2009-04-28 2 views
0

배경 : ASP.NET 2.0을 사용하여 웹 서비스를 만드는 중입니다. 이 웹 서비스는 데이터베이스에서 동적으로 채워진 선택 상자를 포함하는 기존 웹 양식에 다른 인터페이스를 제공합니다.ASP.NET 웹 서비스에서 WSDL 열거 형을 문자열로 매핑

웹 서비스의 첫 번째 초안은 각각의 문자열을 허용 한 다음 유효하지 않은 경우 오류를 반환하여 유효한지 확인했습니다. 그러나 웹 서비스 사용자는 가능한 값이 자주 변경되지 않으므로 WSDL에 열거 된 값을 제공한다는 점에서 질문했습니다.

웹 서비스 코드로 열거 형을 생성하는 것을 꺼려합니다. 대신 생성 된 WSDL 파일을 변경하고 웹 서비스에서 생성하기 위해 클래스를 검사하는 대신이를 사용하도록 지시했습니다.

WSDL :

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://example.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://example.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 
    <wsdl:types> 
    <s:schema elementFormDefault="qualified" targetNamespace="http://example.org/"> 
     <s:element name="MyMethod"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="0" maxOccurs="1" name="myClass" type="tns:MyClass" /> 
      </s:sequence> 
     </s:complexType> 
     </s:element> 
     <s:complexType name="MyClass"> 
     <s:sequence> 
      <s:element minOccurs="0" maxOccurs="1" name="MyString" type="tns:MyStringPossibleValues" /> 
     </s:sequence> 
     </s:complexType> 
     <s:element name="MyMethodResponse"> 
     <s:complexType /> 
     </s:element> 
     <s:simpleType name="MyStringPossibleValues"> 
     <s:restriction base="s:string"> 
      <s:enumeration value="alpha" /> 
      <s:enumeration value="bravo" /> 
     </s:restriction> 
     </s:simpleType> 
    </s:schema> 
    </wsdl:types> 
    <wsdl:message name="MyMethodSoapIn"> 
    <wsdl:part name="parameters" element="tns:MyMethod" /> 
    </wsdl:message> 
    <wsdl:message name="MyMethodSoapOut"> 
    <wsdl:part name="parameters" element="tns:MyMethodResponse" /> 
    </wsdl:message> 
    <wsdl:portType name="ExternalAccessSoap"> 
    <wsdl:operation name="MyMethod"> 
     <wsdl:input message="tns:MyMethodSoapIn" /> 
     <wsdl:output message="tns:MyMethodSoapOut" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:portType name="ExternalAccessHttpGet" /> 
    <wsdl:portType name="ExternalAccessHttpPost" /> 
    <wsdl:binding name="ExternalAccessSoap" type="tns:ExternalAccessSoap"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="MyMethod"> 
     <soap:operation soapAction="http://example.org/MyMethod" style="document" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:binding name="ExternalAccessSoap12" type="tns:ExternalAccessSoap"> 
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="MyMethod"> 
     <soap12:operation soapAction="http://example.org/MyMethod" style="document" /> 
     <wsdl:input> 
     <soap12:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap12:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
</wsdl:definitions> 

를 Webservice :

namespace Example.Service 
{ 
    [WebService(Namespace = "http://example.org/")] 
    [WebServiceBinding(
     ConformsTo = WsiProfiles.BasicProfile1_1, 
     Location="ExternalAccess.wsdl", 
     Name="ExternalAccessSoap", 
     Namespace = "http://example.org/")] 
    [ToolboxItem(false)] 
    public class ExternalAccess : System.Web.Services.WebService 
    { 
     public class MyClass 
     { 
      public string MyString; 
     } 

     [WebMethod] 
     [SoapDocumentMethod(
      Action = "http://example.org/MyMethod", 
      RequestNamespace = "http://example.org/", 
      Binding="ExternalAccessSoap")] 
     public void MyMethod(MyClass myClass) 
     { 
     } 
    } 
} 

문제 다음 WSDL은 MyString에 대한리스트를 지정하고, 코드 스트링 타입 ASP 지정 한다. NET에서는 필드를 올바르게 매핑 할 수 없습니다.

디시리얼라이저가 문자열 필드에 열거 형 값을 채우도록 지시 할 수있는 속성이 있습니까?

감사합니다,

매트

답변

1

내가 MyString 실제로 내 웹 서비스로 전송되지 않는 것을 발견 나를 위해이 작업을 수행 할 수있는 비누 확장을 만드는 과정을 거친 데.

이 서비스의 테스트 응용 프로그램이 .NET에서도 작성되었으며 요청 개체를 작성할 때 생성 된 프록시 클래스의 MyStringSpecified 속성을 간과 한 것입니다. 그 결과 SOAP 요청의 일부로 열거 된 값이 전송되지 않았습니다.

이 속성을 true로 설정하면 열거 형 값이 웹 서비스의 MyString 필드에 지정되었습니다.

관련 문제