运行axis2客户端版本1.5 [英] running an axis2 client version 1.5

查看:154
本文介绍了运行axis2客户端版本1.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我没有想法试图让客户端连接到我通过axis2运行的SOAP服务。

So I'm running out of ideas to try to actually get a client to connect to the SOAP service I'm running through axis2.

我尝试了两种方法,一个是使用wsdl2java来构建存根和关联的客户端类,然后编写一个Client类来构建请求消息并通过Stub发送它们。另一种方法是使用ServiceClient进行连接..

I tried two methods, one was to use wsdl2java to build the stub and associated client side classes, and then write a Client class that build the requests messages and sends them through the Stub. The other way was to use the ServiceClient to connect..

两者都以自己的方式失败..

Both are failing in their own way..

选项#1,每次通过存根发送消息时我都会回复:

Option #1, every time a message is sent through the stub I get this back:

org.apache.axis2.AxisFault: The input stream for an incoming message is null.
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:87)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)

选项#2,每次运行时我都会遇到此异常:

Option #2, everytime I run it I get this Exception:

org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.local.LocalTransportSender

选项#2来源:

import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory; 
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.Constants;
import org.apache.axis2.client.ServiceClient;

public class loyaltyClient {

    private static EndpointReference targetEPR = 
         new EndpointReference(
           "http://localhost:8080/axis2/services/service");

    public static OMElement verifyCustomer(String customer_id) {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace(
                "http://localhost/", "service");
        OMElement method = fac.createOMElement("VerifyCustomer", omNs);
        OMElement value1 = fac.createOMElement("customer_id",omNs);
        OMElement value2 = fac.createOMElement("source_id",omNs);
        OMElement value3 = fac.createOMElement("source_password",omNs);
        OMElement value4 = fac.createOMElement("source_txnid",omNs);
        OMElement value5 = fac.createOMElement("timestamp",omNs);

value1.addChild(fac.createOMText(value1, customer_id));
value2.addChild(fac.createOMText(value2, "source"));
value3.addChild(fac.createOMText(value3, "1234"));
value4.addChild(fac.createOMText(value4, "123"));
value5.addChild(fac.createOMText(value5, "06-01-2010 12:01:01"));
        method.addChild(value1);
        method.addChild(value2);
        method.addChild(value3);
        method.addChild(value4);
        method.addChild(value5);
        return method;
    }

    public static void main(String[] args) {
        try {
            OMElement vctest = loyaltyClient.verifyCustomer("6177740603");
            Options options = new Options();
            options.setTo(targetEPR);

options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

            ServiceClient sender = new ServiceClient();
            sender.setOptions(options);
            OMElement result = sender.sendReceive(vctest);

            String response = result.getFirstElement().getText();
            System.out.println(response);

        } catch (Exception e) { //(XMLStreamException e) {
            System.out.println(e.toString());
        }
    }

}

推荐答案

在使用Axis连接到.Net服务提供商时,我也遇到了错误传入消息的输入流为空。

I've also encountered the error "The input stream for an incoming message is null" while using Axis to connect to a .Net service provider.

问题在于.Net不支持称为分块编码的功能,默认情况下,Axis会以块为单位打破其请求头,这被假定为符合HTTP 1.1的内容。

The problem is that .Net doesn't not support a feature called "chunked encoding", by default Axis will break its request header in chunks which is suppose to be a HTTP 1.1 compliant thing.

无论如何,您可以通过执行以下操作在Axis中关闭此功能:

Anyway, you can turn this feature off in Axis by doing the following:

// Turn off the Axsis Chunked feature, some service providers (like .Net) don't support chunked headers.
Options options = serviceClient.getOptions();
options.setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
serviceClient.setOptions(options);            

这对我有用。在处理.Net服务时要确保的另一件事是能够指定端口名称并确保消息有效负载具有每个元素的命名空间前缀。

This worked for me. Another thing to make sure of when dealing with .Net services is to be able to specify the port name and make sure your message payload has the namespace prefix for each element.

希望这些信息可以帮助某人。

Hope this info helps somebody.

干杯,
DC

Cheers, DC

这篇关于运行axis2客户端版本1.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆