`

网上WebService测试及使用

阅读更多

网上有一些网站提供的WebService,可用作测试。如下地址就是一个提供英汉互译的WebService

 

Endpoint: http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx


Disco: http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx?disco


WSDL: http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx?wsdl

 

 

你可以直接在浏览器地址栏里输入:

http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx/getEnCnTwoWayTranslator?Word=hello

就能得到一个得到调用的xml格式的结果,这里getEnCnTwoWayTranslator是方法名,Word是参数名,如果你想汉译英的话就需要传递中文参数,但是你不能直接   Word=你好    这样传中文参数,要先转换成unicode格式,这样才能作为url参数正常传递,就像这样:

http://www.webxml.com.cn/WebServices/TranslatorWebService.asmx/getEnCnTwoWayTranslator?Word=%u4F60%u597D

 

 

你如果有xml处理工具的话,比如xmlspy这种,你可以根据WSDL地址直接构造一个soap协议封装的xml发送给服务端,代码可能向这种样子:

<?xml version="1.0" encoding="utf-8"  ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

	<SOAP-ENV:Body>
	
		<m:getEnCnTwoWayTranslator xmlns:m="http://WebXml.com.cn/">
			<m:Word>hello</m:Word>
		</m:getEnCnTwoWayTranslator>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

如上soap xml发送英文参数没问题,但是发送中文参数就不能正常识别,这时候我们可以把编码方式改为utf-16,这样就能正常发送中文了。

<?xml version="1.0" encoding="utf-16"  ?>

(注:直接设置成GBK或GB2312都不成功,不知为何)

 

 

http://www.webxml.com.cn这个网站上还有不少其他的测试用WebService,大家可以去看看。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics