Запрос веб-службы корректно обрабатывается в интерфейсе Soap, но не в программе Java - PullRequest
0 голосов
/ 24 января 2012

Мы пытаемся идентифицировать текст на изображении, используя веб-сервис: www.ocrwebservice.com Он обслуживается должным образом с помощью интерфейса Soap, и мы получаем распознанный текст в ответ:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">

<wsa:Action>http://stockservice.contoso.com/wse/samples/2005/10/OCRWebServiceRecognizeResponse</wsa:Action>
      <wsa:MessageID>urn:uuid:14db681a-8f8b-4fb6-8de3-a5a122e07a43</wsa:MessageID>
      <wsa:RelatesTo>urn:uuid:ca0891c2-6838-45b0-8691-37909c69cdd9</wsa:RelatesTo>
      <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
      <wsse:Security>
         <wsu:Timestamp wsu:Id="Timestamp-16f0eade-c981-400b-ac8e-1fe49ed1358e">
            <wsu:Created>2012-01-24T11:31:46Z</wsu:Created>
            <wsu:Expires>2012-01-24T11:36:46Z</wsu:Expires>
         </wsu:Timestamp>
      </wsse:Security>
   </env:Header>
   <soap:Body>
      <OCRWebServiceRecognizeResponse xmlns="http://stockservice.contoso.com/wse/samples/2005/10">
         <OCRWSResponse>
            <ocrText/>
            <errorMessage>Recognized Words not available</errorMessage>
            <ocrWSWords/>
         </OCRWSResponse>
      </OCRWebServiceRecognizeResponse>
   </soap:Body>
</soap:Envelope>

Но если мы попытаемся использовать тот же сервис через Java-программу, мы получим следующую ошибку:

<errorMessage>Invalid user name</errorMessage>

Хотя имя пользователя и код лицензии являются частью самого запроса веб-сервиса.И это было проверено, чтобы быть действительным через пользовательский интерфейс SOAP.Программа указана ниже:

public class CallingWS
{
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        StringBuffer _buf = new StringBuffer();
        Vector respElements = new Vector();

        try
        {
            System.getProperties().put("http.proxyHost", "proxy.OurOrganisation.com");
            System.getProperties().put("http.proxyPort", "1234");
            String endpointURL = "http://www.ocrwebservice.com/services/OCRWebService.asmx?WSDL";
            System.out.println((new StringBuilder()).append("endpointURL: ").append(endpointURL).toString());
            Service service = new Service();
            Call call = (Call)service.createCall();
            call.setTargetEndpointAddress(new URL(endpointURL));
            SOAPBodyElement requestElements[] = new SOAPBodyElement[1];
            call.setSOAPActionURI("http://stockservice.contoso.com/wse/samples/2005/10/OCRWebServiceRecognize");
            String request="T H E     C O M P L E T E    R E Q U E S T    working in SOAP UI";
            InputStream requestStream = new ByteArrayInputStream(request.getBytes());
            requestElements[0] = new SOAPBodyElement(requestStream);
            call.setTimeout(200000);
            respElements = (Vector)call.invoke(requestElements);

            _buf.append(((SOAPBodyElement)respElements.get(0)).toString());
            _buf.append("\n");

            System.out.println(_buf.toString());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

В нашей организации существует брандмауэр.И прокси нужен для отправки запроса.Что может быть не так?

...