1

我已经红色并尝试了多个 SOAP 消息。我试图将它们粘贴到我的解决方案中,但无法得到答案。

我使用这个 Groovy 代码发送 SOAP 请求并获得 SOAP 应答。它适用于 2 个网络服务。我使用 SoapUI 来编写我的 XML,而我在这里使用的 XML 正在 SoapUI 上工作,我从服务器得到了答案。

现在我的工作 XML 和工作的 Groovy 脚本(用于其他服务)不能一起工作,我不知道问题出在哪里。我不是开发人员。我遇到了 SSL 错误,但我确定此服务器上没有 SSL 证书,并且使用没有 SSL 的 SoapUI 可以正常工作,并且提供商告诉我没有证书。

你能帮我看看问题出在哪里吗?提前非常感谢。
亲切的问候。安托万

Groovy 脚本:

// Send data
URL url = new URL(url);
HttpURLConnection conn = url.openConnection();
conn.setDoOutput(true);
if( soapaction != null ) conn.setRequestProperty( "SOAPAction", soapaction );
conn.setRequestProperty( "Content-Type", "text/xml" );
String authorizationString = "Basic " + (username + ":" +  password).bytes.encodeBase64();
conn.setRequestProperty ("Authorization", authorizationString);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(xml);
wr.close();

// Get the response
String response;
InputStream responseStream;
try {
    responseStream = conn.getInputStream();
    success = 1;
} catch( IOException e ) {
    success = 0;
    if( conn.getResponseCode() == 500 ) {
        responseStream = conn.getErrorStream();
    } else throw e;
}
response = responseStream.getText("utf-8");
responseStream.close();
return response;

此脚本的一些参数:
XML
soapaction:getAnimals
URL:https
://test.anis.ch/HTDB.WebService/AnimalImportService.asmx 密码:测试
用户名:613731

XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlso.../soap/envelope/" xmlns:urn="urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1" xmlns:urn1="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:getAnimals>
         <urn:getMessage>
            <urn1:Header>
               <urn1:P_Praxisnummer>371066</urn1:P_Praxisnummer>
               <urn1:P_Account>613731</urn1:P_Account>
               <urn1:P_PIN>test</urn1:P_PIN>
            </urn1:Header>
            <urn1:Body>
               <!--1 or more repetitions:-->
               <urn1:KZ_Kennzeichnung>756000100230345</urn1:KZ_Kennzeichnung>
            </urn1:Body>
         </urn:getMessage>
      </urn:getAnimals>
   </soapenv:Body>
</soapenv:Envelope>
4

2 回答 2

4

您可以使用groovy wslite用更少的代码做同样的事情(但可以工作):

@Grab( 'com.github.groovy-wslite:groovy-wslite:0.8.0' )
import wslite.soap.*
import wslite.http.auth.*

def client = new SOAPClient( 'https://test.anis.ch/HTDB.WebService/AnimalImportService.asmx' )

client.authorization = new HTTPBasicAuthorization( "613731", "test" )

// Trust the ssl for this site
client.httpClient.sslTrustAllCerts = true

def response = client.send(SOAPAction:'urn:tvd:heimtierdatenbanksql:webservice:animalimportservcie:v1:getAnimalsIn') {
    body {
        getAnimals( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1' ) {
            getMessage {
                Header( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1' ) {
                    P_Praxisnummer( '371066' )
                    P_Account( '613731' )
                    P_PIN( 'test' )
                }
                Body( 'xmlns':'urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1' ) {
                    KZ_Kennzeichnung( '756000100230345' )
                }
            }
        }
    }
}

println XmlUtil.serialize( response.getAnimalResponse )

手指交叉,为您工作!

我得到:

<tag0:getAnimalResponse xmlns:tag0="urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1">
  <tag0:outputMessage>
    <R_Fehlertext xmlns="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1">Account-Informationen nicht plausibel</R_Fehlertext>
    <R_FehlerCode xmlns="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1">109</R_FehlerCode>
  </tag0:outputMessage>
</tag0:getAnimalResponse>

所以我想我的凭据有问题...

于 2013-11-13T09:28:32.643 回答
0

您必须在脚本中添加下一行:

conn.setRequestProperty( "Content-Type", "charset=utf-8"); 
于 2017-04-18T10:12:55.937 回答