객체

2010-08-06 2 views
0

전달 대 웹 서비스를 통해 직렬화 된 객체를 전달 나는 다음과 같은 네임 스페이스 C# .NET에서 웹 서비스가 있습니다. 이 웹 메서드는 내용이 MyObject의 serialize 된 인스턴스 인 문자열을 반환합니다. 나는 클라이언트 측에서이 메서드를 호출하고 수업을 MyObject이 XML을 역 직렬화 할 때객체

<? Xml version = "1.0" encoding = "utf-16"?> 
<ServiceObject Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<Services> 
<service> 
    <id>3</id> 
    <date>02/08/2010</date> 
</service> 
</Services> 
</ServiceObject> 

I 발생할 문제는 내가 얻을 것이 :

[WebMethod (MessageName = "GetServiceObjectXML" Description = "Get ServiceObject from Server to Client")] 
public string GetServiceObjectXML() 

이 방법은 다음과 같은 XML을 반환 NULL 객체.

는 그 후 나는 다음과 같은 서명 새의 WebMethod를 만들어 :

[WebMethod (MessageName = "GetServiceObject" Description = "Get ServiceObject from Server to Client")] 
public MyObject GetServiceObject() 

나는 개체가 제대로 채워 나는 또한 문제없이 객체를 직렬화 할 수 클라이언트 측에서이 메소드를 호출하지만 때 serialization의 결과는 다음과 같습니다. xml :

<? Xml version = "1.0" encoding = "utf-16"?> 
<ServiceObject Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<Services Xmlns="http://enterpriseName/wsName"> 
<service> 
    <id>3</id> 
    <date>02/08/2010</date> 
</service> 
</Services> 
</ServiceObject> 

이는 WebMethod GetServiceObjectXML에 의해 생성 된 XML과 다릅니다.

같은 웹 서비스와 같은 고객 모두에서 두 가지 방법을 모두 사용할 예정이므로이 문제를 어떻게 해결할 수 있습니까?

답변

1

확실한 대답은 GetServiceObjectXML()이 GetServiceObject()와 동일한 XML을 반환하도록 수정하는 것입니다. 차이점은 프레임 워크에 의해 직렬화 된 객체가 다른 XML 네임 스페이스를 지정하고있는 것으로 보입니다. GetServiceObjectXML()에서 객체를 XML로 직렬화하기 위해 사용하는 모든 메소드는 그렇게하지 않습니다.