14

Axisを使用して.NET2.0Webサービスを利用しようとしています。Eclipse WSTプラグインを使用してWebサービスクライアントを生成しましたが、これまでのところ問題ないようです。

予想されるSOAPヘッダーは次のとおりです。

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

Axisクライアントからこのヘッダーを構成する方法に関するドキュメントは見つかりませんでした。Visual Studio C#Express 2008を使用してクライアントを生成するとAuthentication、2つの文字列属性(UserおよびPassword)で名前が付けられたクラスが生成され、すべてのクライアントメソッドがこのクラスのオブジェクトを最初のパラメーターとして受け取りますが、AxisWSクライアントでは発生しませんでした。

クライアント呼び出しでこのヘッダーを設定するにはどうすればよいですか?

4

4 に答える 4

32

多分あなたはorg.apache.axis.client.Stub.setHeader方法を使うことができますか?このようなもの:

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...
于 2009-04-26T20:05:51.660 に答える
3

ユーザーIDとパスワードでコンテナーを表すオブジェクトがある場合は、次のAuthenticationように実行できます。

import org.apache.axis.client.Stub;

//...

MyAuthObj authObj = new MyAuthObj("userid","password");
((Stub) yourServiceObject).setHeader("urn://your/name/space/here", "partName", authObj);
于 2010-06-15T17:45:10.767 に答える
1

私は同じ問題を抱えており、以下の断片によって解決されました:

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);
于 2013-05-15T16:49:27.573 に答える