我有一个带有WS-security的Web服务。我只能使用我的机器IP地址访问此Web服务,并且只有在我进行正确的WS配置时才能访问。
因此,当在Soap-ui中测试时,我得到了回复! 当我在我的模拟器的浏览器中测试连接时,我得到了wsdl页面!
但是在我的应用程序中实现时,我无法调用Web服务! 我犯了一些非常错误但没有得到的东西!
我用于调用我的网络服务的网址是否正确? 我是否要在模拟器中配置DNS服务器?我该怎么办?
这是我的SOAP请求:
POST http://172.xxx.xxx.xxx:8080/wbb HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 1146
Host: 172.xxx.xxx.xxx:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:ser="http://www.''''.com/wbb/service" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header><wsse:Security 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">
<wsse:UsernameToken wsu:Id="UsernameToken-11">
<wsse:Username>whatever2</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">whatever3</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">whatever4</wsse:Nonce>
<wsu:Created>whatever5</wsu:Created>
</wsse:UsernameToken></wsse:Security></soapenv:Header>
<soapenv:Body>
<ser:RechargeRequest>
<ser:value1>?</ser:value1>
<ser:value2>?</ser:value2>
<!--Optional:-->
<ser:value3>?</ser:value3>
</ser:RechargeRequest>
和我的android代码:
protected String doInBackground(String... params) {
private static final String SOAP_ACTION = "";
private static final String NAMESPACE"http://www.'''''.com/wbb/ws";
private static final String METHOD_NAME="Recharge";
private static final String URL = "http://172.xxx.xxx.xxx:8080/wbb/wbb.wsdl";
SoapPrimitive response = null;
String xml="";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo p1 =new PropertyInfo();
p1.name = "value1";
p1.setValue(params[0]);
request.addProperty(p1);
PropertyInfo p2 =new PropertyInfo();
p2.name = "value2";
p2.setValue(params[1]);
request.addProperty(p2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
// create header
Element[] header = new Element[1];
header[0] = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security");
Element usernametoken = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken");
usernametoken.setAttribute(null, "Id", "UsernameToken-1");
header[0].addChild(Node.ELEMENT,usernametoken);
Element username = new Element().createElement(null, "n0:Username");
username.addChild(Node.IGNORABLE_WHITESPACE,"whatever2");
usernametoken.addChild(Node.ELEMENT,username);
Element pass = new Element().createElement(null,"n0:Password");
pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
pass.addChild(Node.TEXT, "whatever3");
usernametoken.addChild(Node.ELEMENT, pass);
Element nonce = new Element().createElement(null, "n0:Nonce");
nonce.setAttribute(null, "EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
nonce.addChild(Node.TEXT, "whatever3");
usernametoken.addChild(Node.ELEMENT, nonce);
Element created = new Element().createElement(null, "n0:Created");
created.addChild(Node.TEXT, "whatever4");
usernametoken.addChild(Node.ELEMENT, created);
// add header to envelope
envelope.headerOut = header;
Log.i("header", "" + envelope.headerOut.toString());
envelope.dotNet = false;
envelope.bodyOut = request;
envelope.setOutputSoapObject(request);
//HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
URL url = null;
try {
url = new URL(URL);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
HttpTransportSE androidHttpTransport = null;
String host = url.getHost();
int port = url.getPort();
String file = url.getPath();
Log.d("Exception d", "host -> " + host);
Log.d("Exception d", "port -> " + port);
Log.d("Exception d", "file -> " + file);
androidHttpTransport = new KeepAliveHttpsTransportSE(host, port, file, 25000);
Log.i("bodyout", "" + envelope.bodyOut.toString());
try
{
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
xml = androidHttpTransport.responseDump;
response = (SoapPrimitive)envelope.getResponse();
Log.i("myApp", response.toString());
}
catch (SoapFault e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
Log.d("Exception Generated", ""+e.getMessage());
}
return response;
}
抱歉我的英语不好以及错误!