SOAP使用=> SAAJ0537:无效的内容类型。在小程序中

时间:2015-02-18 12:05:46

标签: java c# web-services soap applet

我正在尝试在C#下开发一个应用程序,它有一些Java小程序,当我运行它时,我在Java控制台上看到一个错误:SAAJ0537:内容类型无效。更准确的是这一个:

 feb 18, 2015 12:46:10 PM com.sun.xml.internal.messaging.saaj.soap.MessageImpl identifyContentType
 GRAVE: SAAJ0537: Content-Type no válido. Podría ser un mensaje de error en lugar de un mensaje SOAP
 com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl:    com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
at 
com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(Unknown Source)
at paqSoap.Soap.enviar_y_obtener_string(Soap.java:273)
at paqConfiguracion.ConfiguracionMenu.<init>(ConfiguracionMenu.java:404)
at paqApplet.PruebaMenu.iniciarVariables(PruebaMenu.java:265)
at paqApplet.PruebaMenu.init(PruebaMenu.java:165)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.identifyContentType(Unknown Source)
at com.sun.xml.internal.messaging.saaj.soap.MessageFactoryImpl.createMessage(Unknown Source)
at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(Unknown Source)
... 8 more

如果我没错,它会从标题中说出一些内容。错误的代码是这一个:

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_2_PROTOCOL);
                SOAPMessage message = mf.createMessage();


                System.out.println("El mensaje al principio es:"+message);

                //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,"","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);

                MimeHeaders hd = message.getMimeHeaders();

                String serverURI = soapAction;
                System.out.println("ServerURI en enviar_y_obtener_string es:"+serverURI);
                hd.addHeader("SOAPAction", "http://localhost:3624/getConfig");


                url=leerPropiedades()[2];
                System.out.println("La url es dentro de enviar_y_obtener_string:"+url);
                //Establece la URL del destino
                URL endpoint = new URL(url);

                //Envía el mensaje
                System.out.println("Endpoint es:"+endpoint);

                String msg;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                message.writeTo(baos);
                msg = baos.toString();
                System.out.println("msg es:"+message);



                SOAPMessage response = connection.call(message, endpoint);
                System.out.println("Voy a cerrar la conexión");
                //Cierra la conexión
                connection.close();

                //Obtiene los resultados
                TransformerFactory tf = TransformerFactory.newInstance();
                return response.getSOAPBody().getFirstChild().getTextContent();

            }
            catch (Exception ex) 
            {
                ex.printStackTrace();
                return "";
            }


        }

它失败了,为什么?请问你能帮帮我吗?。非常感谢。错误的一行就是这一行:SOAPMessage response = connection.call(message,endpoint);

当我在浏览器上放入来自C#的asmx时,我有这个:

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>

我的applet所做的消息就是这个:

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

所以看这个,我怎么解决呢?

1 个答案:

答案 0 :(得分:0)

我必须从端点的末尾删除/。做完之后。它有效。