如何查找$post不执行在执行时服务器端错在哪里了

本帖子已过去太久远了,不再提供回复功能。jQuery ajax - ajax() 方法
jQuery ajax - ajax() 方法
通过 AJAX 加载一段文本:
jQuery 代码:
$(document).ready(function(){
$(&#b01&).click(function(){
htmlobj=$.ajax({url:&/jquery/test1.txt&,async:false});
$(&#myDiv&).html(htmlobj.responseText);
HTML 代码:
&div id=&myDiv&&&h2&Let AJAX change this text&/h2&&/div&
&button id=&b01& type=&button&&Change Content&/button&
定义和用法
ajax() 方法通过 HTTP 请求加载远程数据。
该方法是 jQuery 底层 AJAX 实现。简单易用的高层实现见 $.get, $.post 等。$.ajax() 返回其创建的 XMLHttpRequest 对象。大多数情况下你无需直接操作该函数,除非你需要操作不常用的选项,以获得更多的灵活性。
最简单的情况下,$.ajax() 可以不带任何参数直接使用。
注意:所有的选项都可以通过 $.ajaxSetup() 函数来全局设置。
jQuery.ajax([settings])
可选。用于配置 Ajax 请求的键值对集合。
可以通过 $.ajaxSetup() 设置任何选项的默认值。
类型:Object
可选。AJAX 请求设置。所有选项都是可选的。
类型:Boolean
默认值: true。默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。
注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。
beforeSend(XHR)
类型:Function
发送请求前可修改 XMLHttpRequest 对象的函数,如添加自定义 HTTP 头。
XMLHttpRequest 对象是唯一的参数。
这是一个 Ajax 事件。如果返回 false 可以取消本次 ajax 请求。
类型:Boolean
默认值: true,dataType 为 script 和 jsonp 时默认为 false。设置为 false 将不缓存此页面。
jQuery 1.2 新功能。
complete(XHR, TS)
类型:Function
请求完成后回调函数 (请求成功或失败之后均调用)。
参数: XMLHttpRequest 对象和一个描述请求类型的字符串。
这是一个 Ajax 事件。
contentType
类型:String
默认值: &application/x-www-form-urlencoded&。发送信息至服务器时内容编码类型。
默认值适合大多数情况。如果你明确地传递了一个 content-type 给 $.ajax() 那么它必定会发送给服务器(即使没有数据要发送)。
类型:Object
这个对象用于设置 Ajax 相关回调函数的上下文。也就是说,让回调函数内 this 指向这个对象(如果不设定这个参数,那么 this 就指向调用本次 AJAX 请求时传递的 options 参数)。比如指定一个 DOM 元素作为 context 参数,这样就设置了 success 回调函数的上下文为这个 DOM 元素。
就像这样:
$.ajax({ url: &test.html&, context: document.body, success: function(){
$(this).addClass(&done&);
类型:String
发送到服务器的数据。将自动转换为请求字符串格式。GET 请求中将附加在 URL 后。查看 processData 选项说明以禁止此自动转换。必须为 Key/Value 格式。如果为数组,jQuery 将自动为不同值对应同一个名称。如 {foo:[&bar1&, &bar2&]} 转换为 '&foo=bar1&foo=bar2'。
dataFilter
类型:Function
给 Ajax 返回的原始数据的进行预处理的函数。提供 data 和 type 两个参数:data 是 Ajax 返回的原始数据,type 是调用 jQuery.ajax 时提供的 dataType 参数。函数返回的值将由 jQuery 进一步处理。
类型:String
预期服务器返回的数据类型。如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息来智能判断,比如 XML MIME 类型就被识别为 XML。在 1.4 中,JSON 就会生成一个 JavaScript 对象,而 script 则会执行这个脚本。随后服务器端返回的数据会根据这个值解析后,传递给回调函数。可用值:
&xml&: 返回 XML 文档,可用 jQuery 处理。
&html&: 返回纯文本 HTML 信息;包含的 script 标签会在插入 dom 时执行。
&script&: 返回纯文本 JavaScript 代码。不会自动缓存结果。除非设置了 &cache& 参数。注意:在远程请求时(不在同一个域下),所有 POST 请求都将转为 GET 请求。(因为将使用 DOM 的 script标签来加载)
&json&: 返回 JSON 数据 。
&jsonp&: JSONP 格式。使用 JSONP 形式调用函数时,如 &myurl?callback=?& jQuery 将自动替换 ? 为正确的函数名,以执行回调函数。
&text&: 返回纯文本字符串
类型:Function
默认值: 自动判断 (xml 或 html)。请求失败时调用此函数。
有以下三个参数:XMLHttpRequest 对象、错误信息、(可选)捕获的异常对象。
如果发生了错误,错误信息(第二个参数)除了得到 null 之外,还可能是 &timeout&, &error&, &notmodified& 和 &parsererror&。
这是一个 Ajax 事件。
类型:Boolean
是否触发全局 AJAX 事件。默认值: true。设置为 false 将不会触发全局 AJAX 事件,如 ajaxStart 或 ajaxStop 可用于控制不同的 Ajax 事件。
ifModified
类型:Boolean
仅在服务器数据改变时获取新数据。默认值: false。使用 HTTP 包 Last-Modified 头信息判断。在 jQuery 1.4 中,它也会检查服务器指定的 'etag' 来确定数据没有被修改过。
类型:String
在一个 jsonp 请求中重写回调函数的名字。这个值用来替代在 &callback=?& 这种 GET 或 POST 请求中 URL 参数里的 &callback& 部分,比如 {jsonp:'onJsonPLoad'} 会导致将 &onJsonPLoad=?& 传给服务器。
jsonpCallback
类型:String
为 jsonp 请求指定一个回调函数名。这个值将用来取代 jQuery 自动生成的随机函数名。这主要用来让 jQuery 生成度独特的函数名,这样管理请求更容易,也能方便地提供回调函数和错误处理。你也可以在想让浏览器缓存 GET 请求的时候,指定这个回调函数名。
类型:String
用于响应 HTTP 访问认证请求的密码
processData
类型:Boolean
默认值: true。默认情况下,通过data选项传递进来的数据,如果是一个对象(技术上讲只要不是字符串),都会处理转化成一个查询字符串,以配合默认内容类型 &application/x-www-form-urlencoded&。如果要发送 DOM 树信息或其它不希望转换的信息,请设置为 false。
scriptCharset
类型:String
只有当请求时 dataType 为 &jsonp& 或 &script&,并且 type 是 &GET& 才会用于强制修改 charset。通常只在本地和远程的内容编码不同时使用。
类型:Function
请求成功后的回调函数。
参数:由服务器返回,并根据 dataType 参数进行处理后的数据;描述状态的字符串。
这是一个 Ajax 事件。
traditional
类型:Boolean
如果你想要用传统的方式来序列化数据,那么就设置为 true。请参考工具分类下面的 jQuery.param 方法。
类型:Number
设置请求超时时间(毫秒)。此设置将覆盖全局设置。
类型:String
默认值: &GET&)。请求方式 (&POST& 或 &GET&), 默认为 &GET&。注意:其它 HTTP 请求方法,如 PUT 和 DELETE 也可以使用,但仅部分浏览器支持。
类型:String
默认值: 当前页地址。发送请求的地址。
类型:String
用于响应 HTTP 访问认证请求的用户名。
类型:Function
需要返回一个 XMLHttpRequest 对象。默认在 IE 下是 ActiveXObject 而其他情况下是 XMLHttpRequest 。用于重写或者提供一个增强的 XMLHttpRequest 对象。这个参数在 jQuery 1.3 以前不可用。
如果要处理 $.ajax() 得到的数据,则需要使用回调函数:beforeSend、error、dataFilter、success、complete。
beforeSend
在发送请求之前调用,并且传入一个 XMLHttpRequest 作为参数。
在请求出错时调用。传入 XMLHttpRequest 对象,描述错误类型的字符串以及一个异常对象(如果有的话)
dataFilter
在请求成功之后调用。传入返回的数据以及 &dataType& 参数的值。并且必须返回新的数据(可能是处理过的)传递给 success 回调函数。
当请求之后调用。传入返回后的数据,以及包含成功代码的字符串。
当请求完成之后调用这个函数,无论成功或失败。传入 XMLHttpRequest 对象,以及一个包含成功或错误代码的字符串。
$.ajax() 函数依赖服务器提供的信息来处理返回的数据。如果服务器报告说返回的数据是 XML,那么返回的结果就可以用普通的 XML 方法或者 jQuery 的选择器来遍历。如果见得到其他类型,比如 HTML,则数据就以文本形式来对待。
通过 dataType 选项还可以指定其他不同数据处理方式。除了单纯的 XML,还可以指定 html、json、jsonp、script 或者 text。
其中,text 和 xml 类型返回的数据不会经过处理。数据仅仅简单的将 XMLHttpRequest 的 responseText 或 responseHTML 属性传递给 success 回调函数。
注意:我们必须确保网页服务器报告的 MIME 类型与我们选择的 dataType 所匹配。比如说,XML的话,服务器端就必须声明 text/xml 或者 application/xml 来获得一致的结果。
如果指定为 html 类型,任何内嵌的 JavaScript 都会在 HTML 作为一个字符串返回之前执行。类似地,指定 script 类型的话,也会先执行服务器端生成 JavaScript,然后再把脚本作为一个文本数据返回。
如果指定为 json 类型,则会把获取到的数据作为一个 JavaScript 对象来解析,并且把构建好的对象作为结果返回。为了实现这个目的,它首先尝试使用 JSON.parse()。如果浏览器不支持,则使用一个函数来构建。
JSON 数据是一种能很方便通过 JavaScript 解析的结构化数据。如果获取的数据文件存放在远程服务器上(域名不同,也就是跨域获取数据),则需要使用 jsonp 类型。使用这种类型的话,会创建一个查询字符串参数 callback=? ,这个参数会加在请求的 URL 后面。服务器端应当在 JSON 数据前加上回调函数名,以便完成一个有效的 JSONP 请求。如果要指定回调函数的参数名来取代默认的 callback,可以通过设置 $.ajax() 的 jsonp 参数。
注意:JSONP 是 JSON 格式的扩展。它要求一些服务器端的代码来检测并处理查询字符串参数。
如果指定了 script 或者 jsonp 类型,那么当从服务器接收到数据时,实际上是用了 &script& 标签而不是 XMLHttpRequest 对象。这种情况下,$.ajax() 不再返回一个 XMLHttpRequest 对象,并且也不会传递事件处理函数,比如 beforeSend。
发送数据到服务器
默认情况下,Ajax 请求使用 GET 方法。如果要使用 POST 方法,可以设定 type 参数值。这个选项也会影响 data 选项中的内容如何发送到服务器。
data 选项既可以包含一个查询字符串,比如 key1=value1&key2=value2 ,也可以是一个映射,比如 {key1: 'value1', key2: 'value2'} 。如果使用了后者的形式,则数据再发送器会被转换成查询字符串。这个处理过程也可以通过设置 processData 选项为 false 来回避。如果我们希望发送一个 XML 对象给服务器时,这种处理可能并不合适。并且在这种情况下,我们也应当改变 contentType 选项的值,用其他合适的 MIME 类型来取代默认的 application/x-www-form-urlencoded 。
global 选项用于阻止响应注册的回调函数,比如 .ajaxSend,或者 ajaxError,以及类似的方法。这在有些时候很有用,比如发送的请求非常频繁且简短的时候,就可以在 ajaxSend 里禁用这个。
如果服务器需要 HTTP 认证,可以使用用户名和密码可以通过 username 和 password 选项来设置。
Ajax 请求是限时的,所以错误警告被捕获并处理后,可以用来提升用户体验。请求超时这个参数通常就保留其默认值,要不就通过 jQuery.ajaxSetup 来全局设定,很少为特定的请求重新设置 timeout 选项。
默认情况下,请求总会被发出去,但浏览器有可能从它的缓存中调取数据。要禁止使用缓存的结果,可以设置 cache 参数为 false。如果希望判断数据自从上次请求后没有更改过就报告出错的话,可以设置 ifModified 为 true。
scriptCharset 允许给 &script& 标签的请求设定一个特定的字符集,用于 script 或者 jsonp 类似的数据。当脚本和页面字符集不同时,这特别好用。
Ajax 的第一个字母是 asynchronous 的开头字母,这意味着所有的操作都是并行的,完成的顺序没有前后关系。$.ajax() 的 async 参数总是设置成true,这标志着在请求开始后,其他代码依然能够执行。强烈不建议把这个选项设置成 false,这意味着所有的请求都不再是异步的了,这也会导致浏览器被锁死。
$.ajax 函数返回它创建的 XMLHttpRequest 对象。通常 jQuery 只在内部处理并创建这个对象,但用户也可以通过 xhr 选项来传递一个自己创建的 xhr 对象。返回的对象通常已经被丢弃了,但依然提供一个底层接口来观察和操控请求。比如说,调用对象上的 .abort() 可以在请求完成前挂起请求。拒绝访问 | www. | 百度云加速
请打开cookies.
此网站 (www.) 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(399fbdef-ua98).
重新安装浏览器,或使用别的浏览器客户端调用wcfrest服务时,posthttp的数据格式不正确,导致500错误,详细如下:服务端:一个返回实体publicclassHttpState{publicintcode{}
问题描述客户端调用wcfrest服务时,posthttp的数据格式不正确,导致500错误,详细如下:服务端:一个返回实体publicclassHttpState{publicintcode{}publicstringmsg{}publicobjectdata{}}一个商品实体publicclassO2NProductArgs{publicstringProductName{}publicdecimalPrice{}publicstringDetail{}publicstirngMemberID{}}一个添加商品的Rest接口publicinterfaceIProductSvc{[WebInvoke(Method="POST",RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,UriTemplate="AddProduct",BodyStyle=WebMessageBodyStyle.Bare)]HttpStateAddProduct(O2NProductArgsproductArg);}实现接口publicclassProductSvc:IProductSvc{publicHttpStateAddProduct(O2NProductArgsproductArg){varmyState=HttpState();if(productArg==null){myState.code=1;myState.msg="数据不完整";}else{myState.code=0;myState.msg="success";}returnmyS}}客户端:客户端通过httppost的方式调用AddProduct接口(http://localhost:2311/product/AddProduct),这里有问题来了:如果post的数据是Json字符串并且可以转换为O2NProductArgs,调用正常,如果post的数据是一个“abcdefg1234567”这样的字符串,或者是一个不能转换为O2NProductArgs的Json字符串,服务端就会报500错误,导致请求进不到AddProduct(O2NProductArgsproductArg)这个方法里面来,服务端不能把消息发送给客户端,客户端也会收到一个500的异常。期望得到解决的问题,就算客户端post的参数格式不对,也能进到AddProduct方法里面来,并且把消息返回给客户端。请问此问题如何解决?解决方案解决方案二:不能这么写吗?publicHttpStateAddProduct(objectobj){O2NProductArgsproductArg=objasO2NProductAif(productArg==null){.....解决方案三:publicHttpStateAddProduct(objectobj)这样写同样不行,如果传一段字符串过去,照样报500解决方案四:如果接口不带参数publicHttpStateAddProduct(){}能否通过类似Request的方式获取客户端Post过来的数据解决方案五:500错误完全是接口的原因,你模拟一个http请求调试看然后把错误贴出来解决方案六:用Fiddler摸拟过,post的数据格式正确请求结果为200,正常返回结果,如果post的数据格式不正确才会报500解决方案七:用错东西了吧强类型的webService本来就是简化序列化操作,返回HttpState你是想自定义Http的处理过程?那不是HttpModudle或者HttpHandler干的事情吗?解决方案八:你用[FormBody]试试解决方案九:你这东西就不是Wcf该干的事儿非要搞,你定义参数模板classMessage{publicstringJsonData{}//实际参数,随你怎么给publicstringDataTypeName{}//参数类型完整名称publicTypeDataType{returnType.GetType(this.DataTypeName);}}然后判断JsonData反序列化到DataType是否异常解决方案十:返回HttpState只是返回一个消息,这个消息是一个字符串也行,问题不在这,问题是post的字符串如果不能转换为O2NProductArgs,就报500,如果AddProduct方法不带(O2NProductArgsproductArg)参数,则不会报500,那么这样也行,有没有别的办法可以获取到客户端Post过来的字符串,然后在方法体里将获取到的字符串反序列化解决方案十一:引用9楼yxhhuihui的回复:返回HttpState只是返回一个消息,这个消息是一个字符串也行,问题不在这,问题是post的字符串如果不能转换为O2NProductArgs,就报500,如果AddProduct方法不带(O2NProductArgsproductArg)参数,则不会报500,那么这样也行,有没有别的办法可以获取到客户端Post过来的字符串,然后在方法体里将获取到的字符串反序列化8#的回复时间晚还跑上面去了,是一个思路就是把传对象的方法都改为传Message(类似一个工厂),由他进一步提取实际的参数解决方案十二:引用8楼dongxinxi的回复:你这东西就不是Wcf该干的事儿非要搞,你定义参数模板classMessage{publicstringJsonData{}//实际参数,随你怎么给publicstringDataTypeName{}//参数类型完整名称publicTypeDataType{returnType.GetType(this.DataTypeName);}}然后判断JsonData反序列化到DataType是否异常你定义的消息实体也是一个强类型的实体,跟O2NProductArgs没有区别,如果客户端Post的数据不能转换为Message类,还是报500异常。解决方案十三:publicHttpStateAddProduct([FromBody]stringproductArg){}原来你要这样的,前面都说了,这种你应该用HttpHandler,玩什么webservice解决方案十四:引用12楼dongxinxi的回复:publicHttpStateAddProduct([FromBody]stringproductArg){}原来你要这样的,前面都说了,这种你应该用HttpHandler,玩什么webservice加个FromBody属性跟不加没啥区别,publicHttpStateAddProduct([FromBody]stringproductArg)与publicHttpStateAddProduct(stringproductArg)没区别如果post一串字符串没问题,但是post一个对象过来又有问题了,仍然报500;就是想不管客户端传什么类型,传数字也好,字符串也好,Json对象也好,都不报500错误,都能够进到方法里面来,如果传的数据格式不对,让productArg这个参数的值==null就可以了
【云栖快讯】浅析混合云和跨地域网络构建实践,分享高性能负载均衡设计,9月21日阿里云专家和你说说网络那些事儿,足不出户看直播,赶紧预约吧!&&
6款热门基础云产品6个月免费体验;2款产品1年体验;1款产品2年体验
稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率
开发者常用软件,超百款实用软件一站式提供I am totally new to
but I want to build an Android application with
on top of an API publishing its data via WFS. I would like to request data from the API passing them the bounding box parameter to limit the data that will be returned.
Questions:
How can I put the GetFeature object into the SOAP envelope?
How can I use JAXBElement on the Android client? See edit from March 15, 2012
Here are some links to the API that might help to understand their format.
Example: WFS-1.1 GetFeature POST request,
&?xml version="1.0" encoding="UTF-8"?&
&wfs:GetFeature service="WFS" version="1.1.0"
outputFormat="JSON"
xmlns:ogdwien="http://www.wien.gv.at/ogdwien"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" &
&wfs:Query typeName="ogdwien:BAUMOGD"&
&ogc:Filter&
&ogc:BBOX&
&ogc:PropertyName&SHAPE&/ogc:PropertyName&
&gml:Envelope srsName="http://www.opengis.net/gml/srs/epsg.xml#4326"&
&gml:lowerCorner&16.5&/gml:lowerCorner&
&gml:upperCorner&16.3&/gml:upperCorner&
&/gml:Envelope&
&/ogc:BBOX&
&/ogc:Filter&
&/wfs:Query&
&/wfs:GetFeature&
This is the Android code I came up with by now. This is mostly inspirated by . I am totally unsure whether the namespace, methodName and url are correct!
// KSOAP2Client.java
private class MyAsyncTask extends AsyncTask&Void, Void, Object& {
String namespace = "http://www.wien.gv.at/ogdwien";
String methodName = "GetFeature";
String url = "http://data.wien.gv.at/daten/geoserver/wfs";
protected Object doInBackground(Void... voids) {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet =
SoapObject soapObject = new SoapObject(namespace, methodName);
envelope.setOutputSoapObject(soapObject);
// TODO Put request parameters in the envelope. But how?
HttpTransportSE httpTransportSE = new HttpTransportSE(url);
httpTransportSE.debug =
httpTransportSE.call(namespace + methodName, envelope);
return (Object)soapSerializationEnvelope.getResponse();
} catch (Exception exception) {
exception.printStackTrace();
EDIT: March 15, 2012
I managed to get further and I almost reached what seems to be the solution. I found the
for those namespaces used in the XML request and linked them to my project. That allows me to assemble the objects for the request.
// TODO The core libraries won't work with Android.
import javax.xml.bind.JAXBE
import javax.xml.namespace.QN
// TODO Not sure if the versions fit with the service.
import net.opengis.filter.v_1_1_0.BBOXT
import net.opengis.filter.v_1_1_0.FilterT
import net.opengis.filter.v_1_1_0.PropertyNameT
import net.opengis.gml.v_3_1_1.DirectPositionT
import net.opengis.gml.v_3_1_1.EnvelopeT
import net.opengis.wfs.v_1_1_0.GetFeatureT
import net.opengis.wfs.v_1_1_0.QueryT
List&Double& lowerCornerList = new Vector&Double&();
lowerCornerList.add(16.3739);
lowerCornerList.add(48.2195);
List&Double& upperCornerList = new Vector&Double&();
upperCornerList.add(16.3759);
upperCornerList.add(48.2203);
DirectPositionType lowerCornerDirectPositionType = new DirectPositionType();
lowerCornerDirectPositionType.setValue(lowerCornerList);
DirectPositionType upperCornerDirectPositionType = new DirectPositionType();
upperCornerDirectPositionType.setValue(upperCornerList);
EnvelopeType envelopeType = new EnvelopeType();
envelopeType.setSrsName("http://www.opengis.net/gml/srs/epsg.xml#4326");
envelopeType.setLowerCorner(lowerCornerDirectPositionType);
envelopeType.setUpperCorner(upperCornerDirectPositionType);
List&Object& propertyNames = new Vector&Object&();
propertyNames.add(new String("SHAPE"));
PropertyNameType propertyNameType = new PropertyNameType();
propertyNameType.setContent(propertyNames);
// TODO Check parameters of JAXBElement.
JAXBElement&EnvelopeType& e = new JAXBElement&EnvelopeType&(null, null, envelopeType);
BBOXType bboxType = new BBOXType();
bboxType.setPropertyName(propertyNameType);
bboxType.setEnvelope(e);
// TODO Check parameters of JAXBElement.
JAXBElement&BBOXType& spatialOps = new JAXBElement&BBOXType&(null, null, bboxType);
FilterType filterType = new FilterType();
filterType.setSpatialOps(spatialOps);
QueryType queryType = new QueryType();
List&QName& typeNames = new Vector&QName&();
// TODO Check parameters of QName.
typeNames.add(new QName("ogdwien", "BAUMOGD"));
queryType.setTypeName(typeNames);
GetFeatureType featureType = new GetFeatureType();
featureType.setService("WFS");
featureType.setVersion("1.1.0");
featureType.setOutputFormat("JSON");
featureType.setMaxFeatures(new BigInteger("5"));
String namespace = "http://www.wien.gv.at/ogdwien";
String methodName = "GetFeature";
// TODO Is this the correct action?
String action = "http://data.wien.gv.at/daten/wfs?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:BAUMOGD&srsName=EPSG:4326";
String url = "http://data.wien.gv.at/daten/geoserver/wfs";
// TODO Is this the correct way to add GetFeature?
SoapObject soapObject = new SoapObject(namespace, methodName);
PropertyInfo propertyInfo = new PropertyInfo();
propertyInfo.setName("GetFeature");
propertyInfo.setValue(featureType);
soapObject.addProperty(propertyInfo);
Still there are a major problem and some minor problems left. The major problem is that JAXBElement is contained in a core library (javax.xml.bind.JAXBElement) that Android refuses to consume. The minor problems are stated in the comments and TODOs.
EDIT: April 27, 2012
I imagine that something similar might apply to my problem. I haven't tried yet.
EDIT: May, 09, 2012
Here is the
when you try to compile JAXBElement for Android.
解决方案 @JJD i see you left me a msg in
I have a meeting in a while, but i took a look at your question and would be glad to help as much as possible. I see you have a problem reading the schema definition . this ws definition you have is chained one inside the other thats why it confused you reading it:
If you go on :
take the method "GetCapabilities" and let's read it in the Web service definition:
PS:I did not test these but:
namespace i think should be :
(from targetNamespace)
methodName: GetCapabilities
Now You have the request of GetCapabilities:
&!-- REQUEST --&
&xsd:element name="GetCapabilities" type="wfs:GetCapabilitiesType"/&
&xsd:complexType name="GetCapabilitiesType"&
&xsd:annotation&
&/xsd:annotation&
&xsd:complexContent&
&xsd:extension base="ows:GetCapabilitiesType"&
&xsd:attribute name="service" type="ows:ServiceType" use="optional" default="WFS"/&
&/xsd:extension&
&/xsd:complexContent&
&/xsd:complexType&
GetCapabilities has a complex type of the type: GetCapabilitiesType, which you find
in one of the xsd link on this page, precisely "owsGetCapabilities.xsd"
--> After opening it ie, :
You find this complex type definition:
&complexType name="GetCapabilitiesType"&
&annotation&
&documentation&
XML encoded GetCapabilities operation request. This operation
allows clients to retrieve service metadata about a specific service instance.
In this XML encoding, no "request" parameter is included, since the element name
specifies the specific operation. This base type shall be extended by each specific
OWS to include the additional required "service" attribute, with the correct value for that OWS.
&/documentation&
&/annotation&
&sequence&
&element name="AcceptVersions" type="ows:AcceptVersionsType" minOccurs="0"&
&annotation&
&documentation&When omitted, server shall return latest supported version.
&/documentation&
&/annotation&
&/element&
&element name="Sections" type="ows:SectionsType" minOccurs="0"&
&annotation&
&documentation&
When omitted or not supported by server,
server shall return complete service metadata (Capabilities) document.
&/documentation&
&/annotation&
&/element&
&element name="AcceptFormats" type="ows:AcceptFormatsType" minOccurs="0"&
&annotation&
&documentation&
When omitted or not supported by server, server shall return service metadata
document using the MIME type "text/xml".
&/documentation&
&/annotation&
&/element&
&/sequence&
&attribute name="updateSequence" type="ows:UpdateSequenceType" use="optional"&
&annotation&
&documentation&
When omitted or not supported by server,
server shall return latest complete service
metadata document.
&/documentation&
&/annotation&
&/attribute&
&/complexType&
Now this GetCapabilitiesType has elements /attributes:
name="AcceptVersions" of type="ows:AcceptVersionsType" and minOccurs="0" ie can be null
name="Sections" of type="ows:SectionsType" and minOccurs="0" ie can be null
name="AcceptFormats" of type="ows:AcceptFormatsType" and minOccurs="0" ie can be null
name="updateSequence" of type="ows:UpdateSequenceType" and its is optional -->use="optional"
Where to find these attributes definitions?
-->on this same page you have:
AcceptVersionsType is :
&complexType name="AcceptVersionsType"&
&annotation&
&documentation&
Prioritized sequence of one or more specification versions accepted by client, with preferred versions listed first. See Version negotiation subclause for more information.
&/documentation&
&/annotation&
&sequence&
&element name="Version" type="ows:VersionType" maxOccurs="unbounded"/&
&/sequence&
&/complexType&
so AcceptVersionsType has an element
of type: VersionType can be found at xsd owsOperationsMetadata.xsd ( which is on the same link of this page) and on it you have xsd:owsCommon.xsd this is this where VersionType is found
&simpleType name="VersionType"&
&annotation&
&documentation&Specification version for OWS operation. The string value shall contain one x.y.z "version" value (e.g., "2.1.3"). A version number shall contain three non-negative integers separated by decimal points, in the form "x.y.z". The integers y and z shall not exceed 99. Each version shall be for the Implementation Specification (document) and the associated XML Schemas to which requested operations will conform. An Implementation Specification version normally specifies XML Schemas against which an XML encoded operation response must conform and should be validated. See Version negotiation subclause for more information. &/documentation&
&/annotation&
&restriction base="string"/&
&/simpleType&
and sectionsType is:
&complexType name="SectionsType"&
&annotation&
&documentation&
Unordered list of zero or more names of requested sections in complete service metadata document. Each Section value shall contain an allowed section name as specified by each OWS specification. See Sections parameter subclause for more information.
&/documentation&
&/annotation&
&sequence&
&element name="Section" type="string" minOccurs="0" maxOccurs="unbounded"/&
&/sequence&
&/complexType&
(SectionsType has an element of simple type String)
And AcceptFormatsType is:
&complexType name="AcceptFormatsType"&
&annotation&
&documentation&
Prioritized sequence of zero or more GetCapabilities operation response formats desired by client, with preferred formats listed first. Each response format shall be identified by its MIME type. See AcceptFormats parameter use subclause for more information.
&/documentation&
&/annotation&
&sequence&
&element name="OutputFormat" type="ows:MimeType" minOccurs="0" maxOccurs="unbounded"/&
&/sequence&
&/complexType&
(AcceptFormatsType has an element of type MimeType which is found same place as VersionType ie :
&simpleType name="MimeType"&
&annotation&
&documentation&XML encoded identifier of a standard MIME type, possibly a parameterized MIME type. &/documentation&
&/annotation&
&restriction base="string"&
&pattern value="(application|audio|image|text|video|message|multipart|model)/.+(;s*.+=.+)*"/&
&/restriction&
&/simpleType&
and UpdateSequenceType is( it is a simple type not complex type):
&simpleType name="UpdateSequenceType"&
&annotation&
&documentation&
Service metadata document version, having values that are "increased" whenever any change is made in service metadata document. Values are selected by each server, and are always opaque to clients. See updateSequence parameter use subclause for more information.
&/documentation&
&/annotation&
&restriction base="string"/&
&/simpleType&
(UpdateSequenceType is a simple type)
Now i hope it got clearer how to read the schema .
complex type means object unlike simple type (ex: int). When you have complex types, and you are using ksoap2, you have to create local representations in classes (objects) that implements kvmSerializable ( a ksoap2 serialization interface).
Now , you can read my answers to know how to do that on :
,,. I wrote some details which will help you understand how to start coding.
I won't be on my pc for the day. Hope this helps,let me know if anything of wt i said is ambigous.
本文地址: &
我完全陌生,但我想建立一个Android应用程序在一个API,通过世界粮食首脑会议发布的数据之上 。我想从API请求数据传递给它们的边框参数来限制将要返回的数据。
我怎样才能把获得要素对象到SOAP信封?
如何使用的JAXBElement
Android客户端吗? 从号的查看编辑
下面是一些链接可能有助于了解其格式的API。
DescribeFeature
例:WFS-1.1获得要素POST请求,
< XML版本=“1.0”编码=“UTF-8”&GT?;
< WFS:获得要素服务=“WFS”版本=“1.1.0”
OUTPUTFORMAT =“JSON”
的xmlns:ogdwien =“http://www.wien.gv.at/ogdwien”
的xmlns:WFS =“http://www.opengis.net/wfs”
的xmlns:OGC =“http://www.opengis.net/ogc”
的xmlns:GML =“http://www.opengis.net/gml”
的xmlns:XSI =“http://www.w3.org/2001/XMLSchema-instance”
XSI:的schemaLocation =“http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd“>
<世界粮食首脑会议:查询的typeName =“ogdwien:BAUMOGD”>
< OGC:滤光器&
< OGC:BBOX>
< OGC:属性名>形状< / OGC:属性名>
< GML:信封srsName =“http://www.opengis.net/gml/srs/epsg.xml#4326”>
< GML:lowerCorner> 16.5< / GML:lowerCorner>
< GML:upperCorner> 16.3< / GML:upperCorner>
< / GML:信封>
< / OGC:BBOX>
< / OGC:滤光器&
< /世界粮食首脑会议:查询>
< /世界粮食首脑会议:获得要素>
这是Android code我来到了现在。这主要是通过从ksoap2,机器人维基 的在XML请求中使用的命名空间和连接它们我的项目。这使我能够装配该请求的对象。
// TODO核心库将不与Android合作。
进口javax.xml.bind.JAXBE
进口javax.xml.namespace.QN
// TODO不知道是否该版本适合的服务。
进口net.opengis.filter.v_1_1_0.BBOXT
进口net.opengis.filter.v_1_1_0.FilterT
进口net.opengis.filter.v_1_1_0.PropertyNameT
进口net.opengis.gml.v_3_1_1.DirectPositionT
进口net.opengis.gml.v_3_1_1.EnvelopeT
进口net.opengis.wfs.v_1_1_0.GetFeatureT
进口net.opengis.wfs.v_1_1_0.QueryT
名单<双> lowerCornerList =新矢量&双>();
lowerCornerList.add(16.3739);
lowerCornerList.add(48.2195);
名单<双> upperCornerList =新矢量&双>();
upperCornerList.add(16.3759);
upperCornerList.add(48.2203);
DirectPositionType lowerCornerDirectPositionType =新DirectPositionType();
lowerCornerDirectPositionType.setValue(lowerCornerList);
DirectPositionType upperCornerDirectPositionType =新DirectPositionType();
upperCornerDirectPositionType.setValue(upperCornerList);
EnvelopeType envelopeType =新EnvelopeType();
envelopeType.setSrsName(“http://www.opengis.net/gml/srs/epsg.xml#4326”);
envelopeType.setLowerCorner(lowerCornerDirectPositionType);
envelopeType.setUpperCorner(upperCornerDirectPositionType);
名单<对象& propertyNames =新矢量&对象&();
propertyNames.add(新的String(“形”));
PropertyNameType propertyNameType =新PropertyNameType();
propertyNameType.setContent(propertyNames);
//的JAXBElement的TODO检查参数。
的JAXBElement< EnvelopeType> E =新的JAXBElement< EnvelopeType>(NULL,NULL,envelopeType);
BBOXType bboxType =新BBOXType();
bboxType.setPropertyName(propertyNameType);
bboxType.setEnvelope(E);
//的JAXBElement的TODO检查参数。
的JAXBElement< BBOXType> spatialOps =新的JAXBElement< BBOXType>(NULL,NULL,bboxType);
过滤式过滤式=新的过滤式();
filterType.setSpatialOps(spatialOps);
查询类型查询类型=新的查询类型();
名单<的QName> typeNames =新矢量&&的QName GT;();
// QName的TODO检查参数。
typeNames.add(新QName(“ogdwien”,“BAUMOGD”));
queryType.setTypeName(typeNames);
GetFeatureType的FeatureType =新GetFeatureType();
featureType.setService(“世界粮食首脑会议”);
featureType.setVersion(“1.1.0”);
featureType.setOutputFormat(“JSON”);
featureType.setMaxFeatures(新的BigInteger(“5”));
字符串空间=“http://www.wien.gv.at/ogdwien”;
字符串方法名=“获得要素”;
// TODO这是正确的行动?
串动= "http://data.wien.gv.at/daten/wfs?service=WFS&request=GetFeature&version=1.1.0&typeName=ogdwien:BAUMOGD&srsName=EPSG:4326";
字符串URL =“http://data.wien.gv.at/daten/geoserver/wfs”;
// TODO这是增加获得要素的正确方法?
SoapObject soapObject =新SoapObject(命名空间,方法名);
的PropertyInfo的PropertyInfo =新的PropertyInfo();
propertyInfo.setName(“获得要素”);
propertyInfo.setValue(的FeatureType);
soapObject.addProperty(的PropertyInfo);
不过也有一个主要问题,并留下了一些小问题。主要的问题是,的JAXBElement 包含在核心库( javax.xml.bind.JAXBElement )的Android的拒绝消费。次要问题陈述了意见和待办事项。
当我读到我想,类似的东西可能会适用于我的问题。我还没有尝试过。
编辑:五月09,2012
下面是来自Eclipse的的
我有一段时间开会,但我看了看你的问题,并会很乐意帮助尽可能多的。我看到你有一个问题,阅读模式定义。此WS定义你已经是链接一个接一个的多数民众赞成里面为什么会弄得你读它:
如果你去:
取方法“获得性能”,让我们读它在Web服务定义:
PS:我没有测试这些,但是:
命名空间,我认为应该是:(从目标名称)
方法名:获得性能
现在你已经获得性能的要求:
<! - 请求 - >
< XSD:元素的名称=“获得性能”TYPE =“世界粮食首脑会议:GetCapabilitiesType”/>
< XSD:复杂类型的名称=“GetCapabilitiesType”>
< XSD:注释>
< / XSD:注释>
< XSD:复杂内容>
< XSD:扩展底座=“OWS:GetCapabilitiesType”>
< XSD:属性名=“服务式”=“OWS:服务类型”使用=“可选”默认为“WFS”/>
< / XSD:扩展>
< / XSD:复杂内容>
< / XSD:复杂类型>
获得性能有着复杂类型的类型:GetCapabilitiesType,你发现在XSD的一个环节此页,precisely “owsGetCapabilities.xsd” 上
- >打开后即:
您觉得这个复杂类型定义:
<复杂类型名称=“GetCapabilitiesType”>
<标注>
<文件>
XML连接codeD GetCapabilities操作请求。此操作
允许客户以检索服务元数据有关特定服务实例。
在这个XML编码,无“请求”参数被包括,因为该元素名
指定的具体操作。这种基本类型,由每一个具体的延长
OWS包括额外需要的“服务”属性,与该OWS正确的值。
< /文件>
< /注释>
<序列>
&所述;元素名称=“AcceptVersions”类型=“流入:AcceptVersionsType”的minOccurs =“0”>
<标注>
<文件&在省略,服务器将返回最新的支持版本。
< /文件>
< /注释>
< /组件&
<元素名称=“节”TYPE =“OWS:SectionsType”的minOccurs =“0”>
<标注>
<文件>
如果忽略或不支持的服务器,
服务器将返回完整的服务元数据(功能)的文件。
< /文件>
< /注释>
< /组件&
&所述;元素名称=“AcceptFormats”类型=“流入:AcceptFormatsType”的minOccurs =“0”>
<标注>
<文件>
如果忽略或不支持的服务器,服务器将返回服务元数据
使用MIME类型“text / xml”的文件。
< /文件>
< /注释>
< /组件&
< /序列>
<属性名=“UPDATESEQUENCE”TYPE =“OWS:UpdateSequenceType”使用=“可选”>
<标注>
<文件>
如果忽略或不支持的服务器,
服务器将返回最新的完整的服务
元数据文件。
< /文件>
< /注释>
< /属性>
< /复杂类型>
现在这个GetCapabilitiesType有元素/属性:
NAME =“AcceptVersions”TYPE =“OWS:AcceptVersionsType”和的minOccurs =“0”,即可以为空
NAME =“节”TYPE =“OWS:SectionsType”和的minOccurs =“0”,即可以为空
NAME =“AcceptFormats”TYPE =“OWS:AcceptFormatsType”和的minOccurs =“0”,即可以为空
NAME =“UPDATESEQUENCE”类型=“OWS:UpdateSequenceType”,其是可选项 - >使用=“可选”
在哪里可以找到这些属性的定义?
- >同一页面上,你有:
AcceptVersionsType是:
<复杂类型名称=“AcceptVersionsType”>
<标注>
<文件>
优先级由客户端接受的一个或多个规格的版本序列,首先列出preferred版本。见版本协商节以获取更多信息。
< /文件>
< /注释>
<序列>
<元素名称=“版本”TYPE =“OWS:VersionType”的maxOccurs =“无界”/>
< /序列>
< /复杂类型>
所以AcceptVersionsType有类型的元素:VersionType可以在XSD
owsOperationsMetadata.xsd(这是此页的相同的链接)中找到,它必须为xsd:owsCommon.xsd这是该其中,VersionType被发现
<简单类型名称=“VersionType”>
<标注>
<文件>规范版本为OWS操作。该字符串值应包含一个XYZ“版本”值(例如,“2.1.3”)。版本号应包含用小数点隔开,其形式为“XYZ”三非负整数。 Y中的整数和z不得超过99每个版本都应当对执行规范(文件)和相关的XML模式到请求的操作将符合。一个执行规范的版本通常指定XML架构对其中的XML连接codeD操作响应必须符合标准,应验证。见版本协商节以获取更多信息。 < /文件>
< /注释>
<限制性基地=“字符串”/>
< /简单类型>
和sectionsType是:
<复杂类型名称=“SectionsType”>
<标注>
<文件>
在完善的服务元数据文件请求的区段零个或多个名无序列表。每科值必须如规定每个OWS规范允许的节名。见第参数节以获取更多信息。
< /文件>
< /注释>
<序列>
<元素名称=“部分”类型=“字符串”的minOccurs =“0”的maxOccurs =“无界”/>
< /序列>
< /复杂类型>
(SectionsType简单String类型的元素)
和AcceptFormatsType是:
<复杂类型名称=“AcceptFormatsType”>
<标注>
<文件>
优先级的所期望的客户端,首先列出preferred格式的零个或多个GetCapabilities操作响应格式序列。每个响应格式由它的MIME类型进行标识。见AcceptFormats参数使用节以获取更多信息。
< /文件>
< /注释>
<序列>
<元素名称=“OUTPUTFORMAT”TYPE =“OWS:Mime类型”的minOccurs =“0”的maxOccurs =“无界”/>
< /序列>
< /复杂类型>
(AcceptFormatsType有型的MimeType的是发现了同一个地方VersionType即一个元素:的
<简单类型名称=“Mime类型”>
<标注>
<文件> XML EN标准的MIME类型,可能是一个参数化的MIME类型的codeD标识符。 < /文件>
< /注释>
<限制性基地=“字符串”>
&图案值=“(应用程序|音频|图片|文|视频|留言|多部分|型号)/.+(; S * + = +)*”/>
< /限制>
< /简单类型>
和UpdateSequenceType是(这是一个简单的类型并不复杂类型):
<简单类型名称=“UpdateSequenceType”>
<标注>
<文件>
服务元数据文档的版本,具有为值“增加了”当任何变化是在服务元数据文件。值由每个服务器选择,并且总是不透明的客户端。见UPDATESEQUENCE参数使用节以获取更多信息。
< /文件>
< /注释>
<限制性基地=“字符串”/>
< /简单类型>
(UpdateSequenceType是一个简单的类型)
现在我希望它有更清晰的如何读取架构。
现在,复杂类型表示不同于简单类型的对象(如:INT)。当你有复杂类型,并且使用的是ksoap2,你必须创建本地再presentations的类(对象)实现kvmSerializable(一ksoap2串行接口)。
现在,你可以阅读我的回答就知道该怎么做的:
Link1,,.我写了一些细节,这将有助于您了解如何开始编码。
我不会在我的电脑的一天。希望这可以帮助,让我知道,如果重量的什么,我说的是ambigous。
本文地址: &
扫一扫关注官方微信

我要回帖

更多关于 postconstruct 没执行 的文章

 

随机推荐