想了解PythonXMLRPC服务器端和客户端实例的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于python3rpc的相关问题,此外,我们还将为您介绍关于AJAX=Asynchronous
想了解Python XML RPC服务器端和客户端实例的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于python3 rpc的相关问题,此外,我们还将为您介绍关于AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了、Android:Theme.xml 和 Styles.xml?、c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)、Groovy(conncet DB, generate xml, get response xml, compare two xml)的新知识。
本文目录一览:- Python XML RPC服务器端和客户端实例(python3 rpc)
- AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了
- Android:Theme.xml 和 Styles.xml?
- c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)
- Groovy(conncet DB, generate xml, get response xml, compare two xml)
Python XML RPC服务器端和客户端实例(python3 rpc)
一、远程过程调用RPC
XML-RPC is a Remote Procedure Call method that uses XML passed via HTTP as a transport. With it, a client can call methods with parameters on a remote server (the server is named by a URI) and get back structured data. This module supports writing XML-RPC client code; it handles all the details of translating between conformable Python objects and XML on the wire.
简单地,client可以调用server上提供的方法,然后得到执行的结果。类似与webservice。
推荐查看xmlprc的源文件:C:\Python31\Lib\xmlrpc
二、实例
1) Server
代码如下:
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
def div(x,y):
return x – y
class Math:
def _listMethods(self):
# this method must be present for system.listMethods
# to work
return [‘add’, ‘pow’]
def _methodHelp(self, method):
# this method must be present for system.methodHelp
# to work
if method == ‘add’:
return “add(2,3) = 5”
elif method == ‘pow’:
return “pow(x, y[, z]) = number”
else:
# By convention, return empty
# string if no help is available
return “”
def _dispatch(self, method, params):
if method == ‘pow’:
return pow(*params)
elif method == ‘add’:
return params[0] + params[1]
else:
raise ‘bad method’
server = SimpleXMLRPCServer((“localhost”, 8000))
server.register_introspection_functions()
server.register_function(div,”div”)
server.register_function(lambda x,y: x*y, ‘multiply’)
server.register_instance(Math())
server.serve_forever()
2)client
代码如下:
import xmlrpc.client
s = xmlrpc.client.ServerProxy(‘http://localhost:8000’)
print(s.system.listMethods())
print(s.pow(2,3)) # Returns 28
print(s.add(2,3)) # Returns 5
print(s.div(3,2)) # Returns 1
print(s.multiply(4,5)) # Returns 20
3)result
AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了
AJAX
AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。
AJAX 不是新的编程语言,而是一种使用现有标准的新方法。
AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下。
开始学习 AJAX!
什么是 AJAX ?
AJAX = 异步 JavaScript 和 XML。
AJAX 是一种用于创建快速动态网页的技术。
通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新。这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新。
传统的网页(不使用 AJAX)如果需要更新内容,必需重载整个网页面。
有很多使用 AJAX 的应用程序案例:新浪微博、Google 地图、开心网等等。
AJAX 实例解释
上面的 AJAX 应用程序包含一个 div 和一个按钮。
div 部分用于显示来自服务器的信息。当按钮被点击时,它负责调用名为 loadXMLDoc() 的函数:
<html>
<body>
<div id="myDiv"><h3>Let AJAX change this text</h3></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
接下来,在页面的 head 部分添加一个 <script> 标签。该标签中包含了这个 loadXMLDoc() 函数:
<head>
<script type="text/javascript">
function loadXMLDoc()
{
.... AJAX script goes here ...
}
</script>
</head>
下面的章节会为您讲解 AJAX 的工作原理。
Android:Theme.xml 和 Styles.xml?
如何解决Android:Theme.xml 和 Styles.xml??
在较新版本的 Android Studio 中,我看不到 styles.xml
,但在 values 目录中,有两个新的 XML,theme.xml
和 theme.xml(night)
.
它是否真的取代了styles.xml
OR 如果不同,它们之间的区别是什么??
解决方法
styles 是一组属性,用于定义特定 ui 的外观 例如:editText 或 textView 主题同时决定了整个应用的外观(单个主题可以有多种样式取决于您的设计) ),白天和黑夜两种主题的区别在于让您的应用程序适应白天模式和夜间模式。因为现在在 android 操作系统中你可以强制暗模式。
作为开发者,您需要为此准备好您的应用。
如何使用
为您在项目中标记的两个主题赋予不同的颜色(以下来自主题文件)
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.<Your app name>" <---- this is autogenrated this wil be the id to be used
parent="Theme.MaterialComponents.DayNight">
</style>
</resources>
要在 textview 或按钮或布局文件中简单地使用:
<TextView
android:id="@+id/tv_StackOverflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> <---insert your style name inside the theme.
现在,当用户在手机的开发者模式下强制开启暗模式时,您的应用将立即适应它并更改其 UI 的颜色。
可以在此处找到更多信息 - https://developer.android.com/guide/topics/ui/look-and-feel/themes
,在 res\values
中使用 XML 属性实际上并不依赖于文件名,您可以在另一个文件(如 style.xml)中定义任何一个,例如 <string>
。
您甚至可以将 style.xml
的名称更改为您喜欢的名称。
在最近的 Android Studio 版本中,styles.xml
被 themes.xml
取代,但后者为黑暗模式提供了夜间版本。
c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)
这是我得到的错误
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8).
如何更改此使用正确的内容类型?
这是我的配置文件
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="G2WebServiceSoap11Binding" /> </basicHttpBinding> <customBinding> <binding name="G2WebServiceSoap12Binding"> <textMessageEncoding messageVersion="Soap12" /> <httpTransport /> </binding> </customBinding> </bindings> <client> <endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap11Endpoint/" binding="basicHttpBinding" bindingConfiguration="G2WebServiceSoap11Binding" contract="G2ServiceReference.G2WebServicePortType" name="G2WebServiceHttpSoap11Endpoint" /> <endpoint address="http://XXX.XX.XX.XX:XX/janus/services/G2WebService.G2WebServiceHttpSoap12Endpoint/" binding="customBinding" bindingConfiguration="G2WebServiceSoap12Binding" contract="G2ServiceReference.G2WebServicePortType" name="G2WebServiceHttpSoap12Endpoint" /> </client> </system.serviceModel>
这里是堆栈
{System.ServiceModel.ProtocolException: The content type application/xml;charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder,be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '<Exception>org.apache.axis2.AxisFault: The endpoint reference (EPR) for the Operation not found is /janus/services/G2WebService and the WSA Action = null
 at org.apache.axis2.engine.dispatchPhase.checkPostConditions(dispatchPhase.java:89)
 at org.apache.axis2.engine.Phase.invoke(Phase.java:333)
 at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:264)
 at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:163)
 at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:136)
 at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:130)
 at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:829)
 at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:255)
 at com.rm.janus.webservice.GroupCallServlet.doGet(GroupCallServlet.java:33)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
 at javax.servlet.http.HttpSer'. ---> System.Net.WebException: The Remote Server returned an error: (500) Internal Server Error. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace --- Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request,HttpWebResponse response,HttpChannelFactory`1 factory,WebException responseException,ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message,TimeSpan timeout) at System.ServiceModel.dispatcher.RequestChannelBinder.Request(Message message,TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object[] ins,Object[] outs,TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 type) at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request) at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.G2TestApp.G2ServiceReference.G2WebServicePortType.getStudentData(getStudentDataRequest request) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\InetgrisG2TestApp\Service References\G2ServiceReference\Reference.cs:line 2981 at InetgrisG2TestApp.G2ServiceReference.G2WebServicePortTypeClient.getStudentData(ServiceRequest serviceReq) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Service References\G2ServiceReference\Reference.cs:line 2987 at InetgrisG2TestApp.Program.Main(String[] args) in c:\Users\s\Documents\Visual Studio 2012\Projects\G2TestApp\G2TestApp\Program.cs:line 57}
解决方法
更可能的原因是您的服务发生错误,这是返回HTML错误页面.你可以看看this blog post如果你想要的细节.
TL;博士:
错误页面有几种可能的配置.如果您在IIS上托管,则需要删除< httpErrors>部分来自WCF服务的web.config文件.如果没有,请提供您的服务托管场景的详细信息,我可以提出一个编辑来匹配它们.
编辑:
看到您的编辑后,您可以看到正在返回的完整错误. Apache无法确定您要调用哪个服务,并且因此导致错误.一旦您拥有正确的端点,该服务就会正常工作 – 您指向错误的位置.不幸的是,从信息中可以看出正确的位置是什么,但您的操作(当前为空!)或URL不正确.
Groovy(conncet DB, generate xml, get response xml, compare two xml)
import groovy.sql.sql
import groovy.xml.MarkupBuilder
import org.custommonkey.xmlunit.*
//Conect to DB and get the nessecery data to generate the expected Xml.
sql sql=context.dbConnection;
def writer = new StringWriter();
def xml = new groovy.xml.MarkupBuilder(writer)
xml.RetailerGroups(){
RetailerGroup(Name:"Checkout",Id:"CO")
{
Retailers(){
Retailer(Name:"Acme",Id:"Acm")
Retailer(Name:"Acme2",Id:"Acm2")
def res = sql.firstRow("select scdprj.user3 as ''Brand'',"
+ "schedwin.unix_date_conv (scdslg.air_start) as ''StartDate'',"
+ "schedwin.unix_date_conv (scdslg.air_end) as ''EndDate'',"
+ "scdprj.cl_id as AdvertiserId,clnt.name + '' '' + ''-''+ '' '' + user3 as CampaignName,clnt.name as AdvertiserName "
+ "From schedwin.PROJECTS scdprj "
+ "Inner join schedwin.SLGUSAGE scdslg "
+ "ON scdprj.prj_id=scdslg.prj_id "
+ "Join schedwin.CLNT clnt "
+ "ON clnt.cl_id=scdprj.cl_id "
+ "Where scdprj.cl_id=1228 and (scdprj.stat=1) and scdprj.formid=0 "
+ "AND (DATEDIFF(dd,schedwin.unix_date_conv(scdslg.AIR_END),''20090707'') < =0) "
+ "AND (DATEDIFF(dd,schedwin.unix_date_conv(scdslg.AIR_START),''20090707'') >= 0) ")
}
}
RetailerGroup(Name:"Checkout",Id:"CO")
}
def expectedResult = writer.toString()
log.info writer.toString()
XMLUnit.setIgnoreWhitespace(true)
//Get the actual result
def step = testRunner.testCase.testSteps["retailer"]
def result = step.testRequest.response.contentAsstring
log.info result
//Check the actual result by expected result,and output the test result.def xmlDiff = new Diff(result,expectedResult)def s = xmlDiff.toString();File f = new File("c:/","d.txt"); if( !f.exists()){ f.createNewFile(); }try { FileWriter fileWriter = new FileWriter(f,true); if (s == "org.custommonkey.xmlunit.Diff[identical]"){ fileWriter.write("API: ''"+ step.name + "'' DV Result is "+ "Passed/r/n"); } else{ fileWriter.write("API: ''"+ step.name + "'' DV Result is "+ "Failed/r/n"); } fileWriter.close(); } catch (IOException e) { e.printstacktrace(); }
我们今天的关于Python XML RPC服务器端和客户端实例和python3 rpc的分享已经告一段落,感谢您的关注,如果您想了解更多关于AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)开学学习在了、Android:Theme.xml 和 Styles.xml?、c# – 响应消息的内容类型application / xml; charset = utf-8与绑定的内容类型不匹配(text / xml; charset = utf-8)、Groovy(conncet DB, generate xml, get response xml, compare two xml)的相关信息,请在本站查询。
本文标签: