服务器无法识别HTTP标头SOAPAction的值:“”

时间:2015-03-05 10:05:20

标签: java c# web-services soap

我试图从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>

那么它的问题是什么?谢谢和问候

1 个答案:

答案 0 :(得分:0)

我为解决这个问题所做的是在获取正文后将getMimeHeader和addhear写在我的代码顶部