简体   繁体   English

如何将身份验证标头添加到WebService Stub?

[英]How to add Authentication Header to WebService Stub?

I have generated stubs using Apache CXF, IBM Jax-WS and Axis as well in Eclipse and RAD 7.0 . 我已经在Eclipse和RAD 7.0中使用Apache CXF,IBM Jax-WS和Axis生成了存根。

In all the 3 above scenarios it gives me the following exception 在上述所有3种情况下,它给了我以下例外

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: ARERR [149] A user name must be supplied in the control record

After searching i concluded that i have to add Authentication Info to the Soap header created by Client Stubs. 搜索后,我得出结论,我必须将身份验证信息添加到由客户端存根创建的Soap标头中。

i tried the answer on this link 我尝试过此链接的答案

How do you add a Soap Header defined in a wsdl to a web service client in CXF? 如何将wsdl中定义的Soap Header添加到CXF中的Web服务客户端?

but couldn't succeed. 但不能成功。 I am newbie to SOAP and WebServices 我是SOAP和WebServices的新手

So if anyone has worked on it kindly Help. 因此,如果有人进行过帮助,请帮助。

I had this problem a few days ago and it was a headache for me. 几天前我遇到了这个问题,这让我很头疼。 When generating the stubs you have to add a the flag -XadditionalHeaders to the wsimport command. 生成存根时,必须向wsimport命令添加标志-XadditionalHeaders

"C:\Program Files\Java\jdk1.X.X_XX\bin\wsimport.exe" -p com.company.package -keep -XadditionalHeaders -d folder1 http://mywsdllocation.com/doc.wsdl

Where: -p: package that will contain generated classes -keep: keep .java files (otherwise tou'll only get .class files) -XadditionalHeaders: classes for authentication will be created -d: Folder where generated classes will be placed. 其中:-p:包将包含生成的类-keep:保留.java文件(否则tou'll只能获得.class文件)-XadditionalHeaders:类认证将被创建-d:文件夹中生成的类将被放置。

After that, you only have to copy generated java files to your project, under the picked package (com.company.package in this case). 之后,您只需要将生成的Java文件复制到您的项目中,位于选定的包(在本例中为com.company.package)下。 Then you have you create an AuthenticationInfo object and inserting it in the stub method's call, something like this: 然后,您创建了一个AuthenticationInfo对象,并将其插入到stub方法的调用中,如下所示:

WSService service = new WSService(); 
WSPortTypePortType port = service.WSPortTypeSoap();
AuthenticationInfo auth = new AuthenticationInfo();
auth.setUserName(yourUsername);
auth.setPassword(yourPassword);
port.method(param1,param2,auth);

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM