加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice之获得中文、英文双向翻译

发布时间:2020-12-16 23:53:06 所属栏目:安全 来源:网络整理
导读: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

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("你好");
getEnCnTwoWayTranslator("hello");


结果:

<getEnCnTwoWayTranslatorResponse xmlns="http://WebXml.com.cn/"><getEnCnTwoWayTranslatorResult><string>你好: [ n&amp;#464 h&amp;#462o ]</string><string>1. hello |? 2. how are you |</string></getEnCnTwoWayTranslatorResult></getEnCnTwoWayTranslatorResponse> <getEnCnTwoWayTranslatorResponse xmlns="http://WebXml.com.cn/"><getEnCnTwoWayTranslatorResult><string>hello: [ 'hel&amp;#601u,he'l&amp;#601u ]</string><string>int.(见面打招呼或打电话用语)喂,哈罗 |? 词形变化:异体字:hullo 名词复数:hellos 动词过去式:helloed 过去分词:helloed 现在分词:helloing 第三人称单数:helloes ?|</string></getEnCnTwoWayTranslatorResult></getEnCnTwoWayTranslatorResponse>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读