2011-10-04 4 views
0

우리는 프로젝트에 WCF "서비스 참조"를 추가하여 ASMX 서비스를 사용하고 있습니다. 이렇게하면 기본적으로 DataContractSerializer을 사용하고 문제가 발생하면 XmlSerializer으로 되돌아갑니다.WCF 서비스 참조 추가 XmlSerializer로 돌아갑니다

내가의 DataContractSerializer 프록시 클래스를 생성,하지만 난 그렇게 할 때, 그들은 불완전하고 웹 서비스 가 사용하는 사용자 정의 클래스의 모든 누락 (비누, SoapChannel 만의 인터페이스를 떠나 강제로 시도하고 SoapClient 클래스)

글쎄, 뭔가 잘못되어 다시 XmlSerializer 사용으로 떨어지고있다. 참조를 생성 할 때 오류나 경고가 표시되지 않습니다.

DataContractSerializer이 실패하여 XmlSerializer으로 되돌아가는 원인을 어떻게 알 수 있습니까?

+0

wsdl.exe를 사용하여 프록시 클래스를 만드는 것이 더 쉽습니다. –

답변

0

짧은 이야기는 VS가 강제로 DataContractSerializer를 사용할 수 없다는 것입니다. 대신 우리는 webservice를 대표하는 자체 WCF 서비스 계약을 작성했습니다. 우리가 서비스를 소비 할 때 우리는 OWN 서비스 계약을 사용하여 ChannelFactory를 생성합니다. 아래는 채널 생성에 사용 된 코드입니다.

/// <summary> 
/// A generic webservice client that uses BasicHttpBinding 
/// </summary> 
/// <remarks>Adopted from: http://blog.bodurov.com/Create-a-WCF-Client-for-ASMX-Web-Service-Without-Using-Web-Proxy/ 
/// </remarks> 
/// <typeparam name="T"></typeparam> 
public class WebServiceClient<T> : IDisposable 
{ 
    private readonly T channel; 
    private readonly IClientChannel clientChannel; 

    /// <summary> 
    /// Use action to change some of the connection properties before creating the channel 
    /// </summary> 
    public WebServiceClient(string endpointUrl, string bindingConfigurationName) 
    { 
     BasicHttpBinding binding = new BasicHttpBinding(bindingConfigurationName); 

     EndpointAddress address = new EndpointAddress(endpointUrl); 
     ChannelFactory<T> factory = new ChannelFactory<T>(binding, address); 

     this.clientChannel = (IClientChannel)factory.CreateChannel(); 
     this.channel = (T)this.clientChannel; 
    } 

    /// <summary> 
    /// Use this property to call service methods 
    /// </summary> 
    public T Channel 
    { 
     get { return this.channel; } 
    } 

    /// <summary> 
    /// Use this porperty when working with Session or Cookies 
    /// </summary> 
    public IClientChannel ClientChannel 
    { 
     get { return this.clientChannel; } 
    } 

    public void Dispose() 
    { 
     this.clientChannel.Dispose(); 
    } 
} 
관련 문제