从java程序调用web服务

从java程序调用web服务,java,xml,web-services,soap,Java,Xml,Web Services,Soap,我试图通过发送一个xml文件作为输入来调用web服务,我应该会收到一个xml作为回复,但是每当我发送xml时,我都会收到代理身份验证错误,所以我认为我发送了错误的xml,但是当我使用SOAP UI时,相同的xml工作正常,所以我想我的代码可能有问题 下面是代码 URL=null String strUrl="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope\" xmlns:soap=\

我试图通过发送一个xml文件作为输入来调用web服务,我应该会收到一个xml作为回复,但是每当我发送xml时,我都会收到代理身份验证错误,所以我认为我发送了错误的xml,但是当我使用SOAP UI时,相同的xml工作正常,所以我想我的代码可能有问题

下面是代码

URL=null

   String strUrl="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope\" xmlns:soap=\"SoapAuthenticator\" xmlns:ship=\"http://ws.consignorsupport.no/ShipAdvisor\"><soapenv:Header> <soap:ServiceAuthenticationHeader><soap:Username>TDC43671</soap:Username> <soap:Password>hTiNMft/KaMfDDD</soap:Password><soap:IsEncrypted>false</soap:IsEncrypted></soap:ServiceAuthenticationHeader></soapenv:Header><soapenv:Body><ship:SearchForDropPoints><ship:productConceptID>92</ship:productConceptID><ship:installationID>00000000018</ship:installationID><ship:country>DK</ship:country><ship:address></ship:address><ship:postCode>6000</ship:postCode><ship:city></ship:city><ship:limit>5</ship:limit></ship:SearchForDropPoints></soapenv:Body></soapenv:Envelope>";

String ss="http://www.consignorsupport.no/ShipAdvisor/Main.asmx";

url = new URL(ss);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setDoOutput(true);
 conn.setDoInput(true);
conn.setRequestProperty("Content-type", "text/xml");
  conn.setRequestProperty("Accept", "text/xml, application/xml");
  conn.setRequestMethod("POST");

conn.connect();

OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

   wr.write(strUrl);
   wr.flush();
   wr.close();


   int iHttpResponseCode = conn.getResponseCode();
  String  strErrorMessage = conn.getResponseMessage();

  System.out.println("Getting Response status");
  System.out.println(iHttpResponseCode);

  System.out.println(strErrorMessage);
String strUrl=“TDC43671 hTiNMft/KAMFDD920000000018DK60005”;
字符串ss=”http://www.consignorsupport.no/ShipAdvisor/Main.asmx";
url=新url(ss);
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
连接设置输出(真);
conn.setDoInput(真);
conn.setRequestProperty(“内容类型”、“文本/xml”);
conn.setRequestProperty(“接受”、“文本/xml、应用程序/xml”);
conn.setRequestMethod(“POST”);
连接();
OutputStreamWriter wr=新的OutputStreamWriter(conn.getOutputStream());
wr.write(strUrl);
wr.flush();
wr.close();
int iHttpResponseCode=conn.getResponseCode();
字符串strErrorMessage=conn.getResponseMessage();
System.out.println(“获取响应状态”);
System.out.println(iHttpResponseCode);
System.out.println(strErrorMessage);

任何人都能帮我找出哪里出了问题。

如果您遇到proxyauthentication错误,很可能这就是问题所在。可能soap ui设置了正确的代理信息?还是从系统设置中获取?您的java代码不会自动接受这些设置。检查是否配置了系统代理,或者是否在soapUI中配置了系统代理