2009-04-24 1 views
12

Axis를 사용하여 .NET 2.0 웹 서비스를 사용하려고합니다. Eclipse WST 플러그인을 사용하여 웹 서비스 클라이언트를 생성했으며 지금까지는 괜찮은 것 같습니다.Axis 1.4를 사용하여 사용자 정의 SOAP 헤더 설정

여기에 예상되는 SOAP 헤더 :

<soap:Header> 
<Authentication xmlns="http://mc1.com.br/"> 
    <User>string</User> 
    <Password>string</Password> 
</Authentication> 
</soap:Header> 

은 내가 축 클라이언트에서이 헤더를 구성하는 방법에 대한 문서를 찾을 수 없습니다. Visual Studio C# Express 2008을 사용하여 클라이언트를 생성 할 때 두 개의 문자열 특성 (UserPassword)을 사용하는 Authentication 클래스를 생성하고 모든 클라이언트 메서드는이 클래스의 개체를 첫 번째 매개 변수로 받지만 Axis WS 클라이언트.

클라이언트 헤더에이 헤더를 어떻게 설정합니까?

답변

27

아마도 org.apache.axis.client.Stub.setHeader 방법을 사용할 수 있습니까? 이런 식으로 뭔가 : 당신은 사용자 ID와 암호를 사용하여 Authentication 컨테이너를 나타내는 객체가있는 경우

MyServiceLocator wsLocator = new MyServiceLocator(); 
MyServiceSoap ws = wsLocator.getMyServiceSoap(new URL("http://localhost/MyService.asmx")); 

//add SOAP header for authentication 
SOAPHeaderElement authentication = new SOAPHeaderElement("http://mc1.com.br/","Authentication"); 
SOAPHeaderElement user = new SOAPHeaderElement("http://mc1.com.br/","User", "string"); 
SOAPHeaderElement password = new SOAPHeaderElement("http://mc1.com.br/","Password", "string"); 
authentication.addChild(user); 
authentication.addChild(password); 
((Stub)ws).setHeader(authentication); 

//now you can use ws to invoke web services... 
+0

이렇게 많은 좌절감을 겪은 후에야 나는 이것이 필요한 답입니다. 덕분에 – LiorH

+0

이것은 정확히 내가 필요로하는 것이었다! – talanb

+0

'SOAPHeaderElement authentication = new SOAPHeaderElement ("http://mc1.com.br/", "Authentication");'이 문은'abstract class java를 초기화 할 수 없습니다 '라는 오류와 오류를 제공합니다. Salman

2

, 당신과 같이 그것을 할 수 있습니다 :

import org.apache.axis.client.Stub; 

//... 

MyAuthObj authObj = new MyAuthObj("userid","password"); 
((Stub) yourServiceObject).setHeader("urn://your/name/space/here", "partName", authObj); 
+1

어떤 종류의 개체가'MyAuthObj'입니까? 어쩌면 OP를위한 것이'인증'일까요? 그렇다면 어떻게 클라이언트가 이러한 객체를 인스턴스화 할 수 있습니까? ... 감사합니다! – bluish

1

저도 같은 문제를 가지고 아래의 fragment 해결 :

ServiceSoapStub clientStub = (ServiceSoapStub)new ServiceLocator().getServiceSoap(url); 
org.apache.axis.message.SOAPHeaderElement header = new org.apache.axis.message.SOAPHeaderElement("http://www.abc.com/SSsample/","AuthHeader"); 
SOAPElement node = header.addChildElement("Username"); 
node.addTextNode("aat"); 
SOAPElement node2 = header.addChildElement("Password"); 
node2.addTextNode("sd6890"); 

((ServiceSoapStub) clientStub).setHeader(header);