各位,现在有一个地址,使用。net实现的webservice的应用,我客户端用java实现,代码如下:import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.XMLType;import javax.xml.namespace.QName;
import org.apache.axis.message.SOAPHeaderElement;
import java.util.Hashtable;
import org.apache.axis.transport.http.HTTPConstants;
public class wapwbc2 {
    public static void main(String args[]) throws Exception{
       String soapaction="http://www.china-call.com.cn/";      //域名,这是在server定义的      String endPoint ="http://www.china-call.com.cn/webservice/china-call.asmx?wsdl";
      Service service = new Service();
      Call call = (Call) service.createCall();
      Object result;
      try {        Hashtable myhttp = new Hashtable();
        myhttp.put("UserName", "cxuser");
        myhttp.put("UserPwd", "aaa");
        call.setProperty(HTTPConstants.REQUEST_HEADERS, myhttp);        //call.addHeader(header);
        call.setTargetEndpointAddress(new java.net.URL(endPoint));
        call.setOperationName("TempReCall");
        call.addParameter(new QName(soapaction,"srcPhone"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.addParameter("destPhone", XMLType.XSD_STRING, ParameterMode.IN);
        call.setReturnType(XMLType.XSD_STRING);
        result = (Object) call.invoke(new Object[] {"13547821035","87017730"});        System.out.println("result"+result);
      }
      catch (AxisFault fault) {
        result = "Error is: " + fault.toString();
      }
      System.out.println(result);
    }
}各位可以看到,我是用axis的api来调用webservice的,但是现在有个问题。我运行后结果如下:Error is: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: .
   at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
单步调试后执行到result = (Object) call.invoke(new Object[] {"13547821035","87017730"});
时报异常。现在的情况时,按理说我的代码是没有问题的,服务器端加了身份验证,说的时在soap头里面带上用户名密码,我查了很多资料,都没有看到对应的解决方法,请问哪位对webservice比较熟悉的,帮我看看,我到底怎样封装我的soap消息头,才能够通过服务器端的身份验证。谢谢兄弟们。

解决方案 »

  1.   

    有可能是你用SOAP访问webservice,并且在HTTP请求中送了一个SOAPAction的参数,但是这个参数不是service所要求的,所以你最好确定namespace是正确的,并且对照wsdl检查其参数需求...
      

  2.   

    好像有很多嘛,你不要用baidu,baidu能搜到的都是国内的资料,你用google一搜一大堆,不过都是老外的东东,
    要是你En还可以的话,一定能找到解决方案的.
    PS:通常情况下,我的搜索顺序是先baidu(毕竟都是汉字的东西,看着方便^_^),没有好的结果的话就google,而且一定要搜老外的东西,
    通常都能找到解决办法。