服务器未识别HTTP标头SOAPAction的值:“&”;

本文关键字:的值 SOAPAction 识别 HTTP 标头 服务器 | 更新日期: 2024-10-20 11:52:34

我正试图从java应用程序调用web服务,当我试图调用它时,我遇到了下一个错误(web服务在c#下):

soap:ClientSystem.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: "",http://localhost:3624/getConfig.
  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).

我打电话的代码是这样的:

public String enviar_y_obtener_string()   {

            try
            {
                SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
                SOAPConnection connection = scf.createConnection();
                //Crea el mensaje
                MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
                SOAPMessage message = mf.createMessage();

                //Crea las partes del mensaje       
                SOAPPart soapPart = message.getSOAPPart();
                SOAPEnvelope envelope = soapPart.getEnvelope();
                SOAPBody body = envelope.getBody();
                System.out.println("El servidor en enviar_y_obtener_string es:"+servidor+" y el método es:"+metodo);
                //Name n = envelope.createName(metodo,"",servidor);
                Name n = envelope.createName(metodo,"","http://localhost:3624/");   
                SOAPBodyElement soapBodyElement =body.addBodyElement(n);
                for(int i=0;i<lista_nombre_parametros.size();i++)
                {
                    SOAPElement soapElement = soapBodyElement.addChildElement(lista_nombre_parametros.get(i).toString());
                    System.out.println("El nombre del parámetro es:"+lista_nombre_parametros.get(i).toString());
                    int tipo=Integer.valueOf(lista_tipo_parametro.get(i).toString()).intValue();
                    if(tipo==IdTipoCadena){
                        soapElement.addTextNode(lista_valores_parametros.get(i).toString());
                        System.out.println("El valor es:"+ lista_valores_parametros.get(i).toString());
                    }
                    else
                    {
                        SOAPFactory soapFactory = SOAPFactory.newInstance();
                        Name nodeName = envelope.createName("nodo");
                        SOAPElement soapElementint=soapElement.addChildElement(nodeName);
                        ArrayList arraydev=(ArrayList)lista_valores_parametros.get(i);
                        for(int j=0;j<arraydev.size();j++)
                        {
                            Name name3 = envelope.createName("carlos");
                            SOAPElement soapElementhijo=soapElementint.addChildElement(name3);  
                            soapElementhijo.addTextNode("p");
                        }
                    }
                }

                message.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean( true ));
                message.setProperty(Call.SOAPACTION_URI_PROPERTY,url);

                String serverURI = soapAction;

                url=leerPropiedades()[2];
                //Establece la URL del destino
                URL endpoint = new URL(url);
                //Envía el mensaje
                System.out.println("Endpoint es:"+endpoint);
                System.out.println(message.getMimeHeaders());
                String msg;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                message.writeTo(baos);
                msg = baos.toString();
                System.out.println("msg es:"+msg);
                MimeHeaders hd = message.getMimeHeaders();
                hd.addHeader("Content-Type", "text/xml; charset=utf-8");
                hd.addHeader("soapAction",soapAction+"getConfig");

                message.saveChanges();
                SOAPMessage response = connection.call(message, endpoint);
                //Cierra la conexión
                connection.close();
                //Obtiene los resultados
                TransformerFactory tf = TransformerFactory.newInstance();
                System.out.println("He pasado tf y el response es:"+response.getSOAPBody().getFirstChild().getTextContent());
                return response.getSOAPBody().getFirstChild().getTextContent();
            }
            catch (Exception ex) 
            {
                ex.printStackTrace();
                return "";
            }

        }

web服务所在的代码是这样的:

[WebService(Namespace = "http://localhost:3624/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Soa : System.Web.Services.WebService
{
   public Soa()
   {
    //Eliminar la marca de comentario de la línea siguiente si utiliza los componentes diseñados 
    //InitializeComponent(); 
   }
   [WebMethod]
   public string getConfig(string id)
   {
      Datos.Depuracion.setDepuracion("Entrando en getConfig");
      ConfigSOA configuracion = new ConfigSOA();
      String correo = System.Configuration.ConfigurationManager.AppSettings["Correo"];
      String password = System.Configuration.ConfigurationManager.AppSettings["PwdCorreo"];
      try
      {
         Datos.Depuracion.setDepuracion("Peticion de configuracion. ID=" + id);
         if (Int64.Parse(id) > 0)
         {
            //Almacenamos resultados
            String x;
            x = configuracion.getXMLConfig(Int64.Parse(id));
            return (x);
         }
         else
         {
            //Es una prueba
            String x;
            x = (configuracion.getXMLConfigPrueba((-1) * Int64.Parse(id)));
            Datos.Depuracion.setDepuracion(x);
            return x;
         }
     }
     catch (Exception e)
     {
        Email depuracion = new Email(correo, correo, "Depuracion catch", e.Message);
        return null;
     }
  }

Web服务正在等待的请求示例如下:

POST /web/soa/soa.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://localhost:3624/getConfig"
<?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
  <getConfig xmlns="http://localhost:3624/">
    <id>string</id>
  </getConfig>
</soap:Body>

我的信息要求是:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
     <SOAP-ENV:Body>
       <getConfig xmlns="http://localhost:3624/">
         <id>1644</id>
       </getConfig>
     </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

那么问题出在哪里呢?。感谢并问候

服务器未识别HTTP标头SOAPAction的值:“&”;

我解决这个问题的方法是在获得主体后在代码顶部编写getMimeHeader和addhear