2011-03-01 5 views
1

우리는 Spring-WS로 웹 서비스를 구축했으며 C# .NET 클라이언트에서 액세스하려고합니다. 서비스는 SoapUI 및 기타 Java 클라이언트에서 수행 한 모든 테스트에서 정상적으로 작동하지만 .NET에서 멈추게됩니다..NET C# 클라이언트의 Java Webservice - 네임 스페이스 글리치?

네임 스페이스에 문제가있는 것으로 보입니다.

예를 들어,이 요청 작업, 이름 공간은 봉투 태그에 선언 할 때, 어떤 요소는 이름 공간 접두사 거기에 없습니다 :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns="http://mycompany.org/schemas"> 
<soapenv:Header/> 
<soapenv:Body> 
    <authenticationRequest> 
    <username>user</username> 
    <password>password</password> 
</authenticationRequest> 
</soapenv:Body> 
</soapenv:Envelope> 

그러나,이 겉으로는 해당 요청이 작동하지 않습니다 :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://mycompany.org/schemas"> 
<soapenv:Header/> 
<soapenv:Body> 
    <authenticationRequest xmlns="http://mycompany.org/schemas"> 
    <username>user</username> 
    <password>password</password> 
</authenticationRequest> 
</soapenv:Body> 
</soapenv:Envelope> 

이 경우 namespace는 authenticationRequest 요소에서 다시 선언됩니다. 주어진 오류는 요청이 XML 스키마에 대해 유효성을 검사하지 않으며 'username'요소가 정의되지 않았다는 불평입니다.

불행히도 .NET에서 서비스 참조 (및 웹 참조)를 추가 할 때 wsdl.exe에 의해 생성 된 코드는 항상 두 번째 경우에서 요청을 만듭니다.

왜이 두 가지 XML이 동등하지 않으며 C# 클라이언트에서 우리가 할 수있는 이유를 설명해 줄 수 있습니까?
- 두 번째 네임 스페이스 선언을 제거 하시겠습니까?
- 요청의 모든 요소에 네임 스페이스 접두사를 추가 하시겠습니까?
- 또는 각 요소 앞에 접두사가없는 네임 스페이스 선언을 추가 하시겠습니까? 우리는

감사합니다!

답변

0

내가 .NET 클라이언트에서 자바 WS 접근과 비슷한 문제를 했어 :(시간 동안 노력했습니다

는. 나는 문제에 대한 우아한 해결책을 찾았지만, havent 한

  1. 이처럼 SoapExtensionAttribute 구현 :

    나는 SoapExtension으로 수신/발신 SOAP 메시지를 변경하여 그것을 해결 않았다
  2. 0 이런 SoapExtension를 구현 : 같은 철저한 대응을위한

    class SoapExt : SoapExtension 
    { 
        private Stream mWireStream = null; 
        private Stream mApplicationStream = null; 
    
        public override object GetInitializer(Type serviceType) 
        { 
         return serviceType; 
        } 
    
        public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) 
        { 
         return (SoapExtAttribute)attr; 
        } 
    
        public override void Initialize(object initializer) 
        { 
        } 
    
        public override Stream ChainStream(Stream stream) 
        { 
         mWireStream = stream; 
         mApplicationStream = new MemoryStream(); 
         return mApplicationStream; 
        } 
    
    
        public override void ProcessMessage(SoapMessage message) 
        { 
         StreamWriter writer = null; 
         bool fIsServer = (message.GetType() == typeof(SoapServerMessage)); 
         switch (message.Stage) 
         { 
          case SoapMessageStage.BeforeDeserialize: 
           string resp = new StreamReader(mWireStream).ReadToEnd(); 
           StreamWriter w = new StreamWriter(mApplicationStream); 
           w.WriteLine(resp); 
           w.Flush(); 
           mApplicationStream.Seek(0, SeekOrigin.Begin); 
           break; 
          case SoapMessageStage.AfterSerialize: 
           mApplicationStream.Seek(0, SeekOrigin.Begin); 
           string reqXml = new StreamReader(mApplicationStream).ReadToEnd(); 
    
           XmlDocument doc = new XmlDocument(); 
           doc.LoadXml(reqXml); 
    
           Modify(doc); 
    
           reqXml = doc.InnerXml; 
    
           mApplicationStream.Seek(0, SeekOrigin.Begin); 
           writer = new StreamWriter(mWireStream); 
           writer.WriteLine(reqXml); 
           writer.Flush(); 
    
           XmlDocument d = new XmlDocument(); 
           d.LoadXml(reqXml); 
           ServiceManager.RequestSoap = d.LastChild.OuterXml; 
           break; 
         } 
        } 
    
        private void Modify(XmlDocument doc) 
        { 
         // Change the doc in whatever way you want, e.g. remove/add the prefixes 
        } 
    } 
    
+0

안녕하세요, 감사합니다! 하지만 불행히도 C#/.NET/webServices에는별로 경험이 없습니다. 서비스 레퍼런스를 추가 한 후 생성 된 클래스에이 코드를 어디에 넣어야하는지 설명해 주시겠습니까? – npintos

+0

마침내 우리는 그걸 작동하도록 만들었습니다. 비누 요청을 차단하려면 웹 메서드 선언을 통해 [SoapExt] 을 추가하기 만하면됩니다. – npintos

+0

예, 죄송합니다, 나는 그 것을 잊어 버렸습니다 :) – nogola