webservice之获得中文、英文双向翻译
webservice地址:http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx?op=getEnCnTwoWayTranslator soap协议: SOAP 1.1 以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。 POST /WebServices/TranslatorWebService.asmx HTTP/1.1 Host: www.webxml.com.cn Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://WebXml.com.cn/getEnCnTwoWayTranslator" <?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> <getEnCnTwoWayTranslator xmlns="http://WebXml.com.cn/"> <Word>string</Word> </getEnCnTwoWayTranslator> </soap:Body> </soap:Envelope> HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?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> <getEnCnTwoWayTranslatorResponse xmlns="http://WebXml.com.cn/"> <getEnCnTwoWayTranslatorResult> <string>string</string> <string>string</string> </getEnCnTwoWayTranslatorResult> </getEnCnTwoWayTranslatorResponse> </soap:Body> </soap:Envelope> SOAP 1.2 以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。 POST /WebServices/TranslatorWebService.asmx HTTP/1.1 Host: www.webxml.com.cn Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <getEnCnTwoWayTranslator xmlns="http://WebXml.com.cn/"> <Word>string</Word> </getEnCnTwoWayTranslator> </soap12:Body> </soap12:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <getEnCnTwoWayTranslatorResponse xmlns="http://WebXml.com.cn/"> <getEnCnTwoWayTranslatorResult> <string>string</string> <string>string</string> </getEnCnTwoWayTranslatorResult> </getEnCnTwoWayTranslatorResponse> </soap12:Body> </soap12:Envelope> 代码如下: private static void getEnCnTwoWayTranslator(String word) { try { String soapBindingAddress = "http://webservice.webxml.com.cn/webservices/TranslatorWebService.asmx"; ServiceClient sender = new ServiceClient(); EndpointReference endpointReference = new EndpointReference( soapBindingAddress); Options options = new Options(); options.setAction("http://WebXml.com.cn/getEnCnTwoWayTranslator"); options.setTo(endpointReference); sender.setOptions(options); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/","getEnCnTwoWayTranslator"); OMElement data = fac.createOMElement("getEnCnTwoWayTranslator",omNs); String[] strs = new String[] { "Word" }; String[] val = new String[] { word }; for (int i = 0; i < strs.length; i++) { OMElement inner = fac.createOMElement(strs[i],omNs); inner.setText(val[i]); data.addChild(inner); } OMElement result = sender.sendReceive(data); System.out.println(result.toString()); } catch (AxisFault ex) { ex.printStackTrace(); } } 调用: getEnCnTwoWayTranslator("你好"); 结果: <getEnCnTwoWayTranslatorResponse xmlns="http://WebXml.com.cn/"><getEnCnTwoWayTranslatorResult><string>你好: [ n&#464 h&#462o ]</string><string>1. hello |? 2. how are you |</string></getEnCnTwoWayTranslatorResult></getEnCnTwoWayTranslatorResponse> <getEnCnTwoWayTranslatorResponse xmlns="http://WebXml.com.cn/"><getEnCnTwoWayTranslatorResult><string>hello: [ 'hel&#601u,he'l&#601u ]</string><string>int.(见面打招呼或打电话用语)喂,哈罗 |? 词形变化:异体字:hullo 名词复数:hellos 动词过去式:helloed 过去分词:helloed 现在分词:helloing 第三人称单数:helloes ?|</string></getEnCnTwoWayTranslatorResult></getEnCnTwoWayTranslatorResponse> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |