0

我有 1 个带有 .Net 的网络服务,并返回如下值:

<People>
<Person Name="Nick"/>
<Person Name="Nick"/>
</People>

而且我还按照本教程在我的 worklight 应用程序链接中调用 webservice 。但是我遇到了一些错误:

{
   "errors": [
      "Content is not allowed in prolog.",
      "Failed to parse the payload from backend (procedure: HttpRequest)"
   ],
   "info": [
   ],
   "isSuccessful": false,
   "responseHeaders": {
      "Cache-Control": "private",
      "Connection": "Close",
      "Content-Length": "457",
      "Content-Type": "text\/plain; charset=utf-8",
      "Date": "Thu, 13 Jun 2013 02:47:56 GMT",
      "Server": "ASP.NET Development Server\/10.0.0.0",
      "X-AspNet-Version": "2.0.50727"
   },
   "responseTime": 0,
   "statusCode": 500,
   "statusReason": "Internal Server Error",
   "totalTime": 141,
   "warnings": [
   ]
}

这是 myadapert.xml 中的配置:

<protocol>http</protocol>
<domain>localhost</domain>
<port>3923</port>
<procedure name="getperson"/>

在 myadapter-impl.js 的配置中:

function getperson() {
    var input = {
            method : 'get',
            returnedContentType : 'xml',          
            path : "/Service1.asmx/MyMethod"
        };
        return WL.Server.invokeHttp(input);
}

谢谢你的帮助 !

更新

当我将“returnedContentEncoding”xml 更改为 plain.i 时出现此错误:

{
   "errors": [
   ],
   "info": [
   ],
   "isSuccessful": true,
   "responseHeaders": {
      "Cache-Control": "private",
      "Connection": "Close",
      "Content-Length": "457",
      "Content-Type": "text\/plain; charset=utf-8",
      "Date": "Thu, 13 Jun 2013 02:28:38 GMT",
      "Server": "ASP.NET Development Server\/10.0.0.0",
      "X-AspNet-Version": "2.0.50727"
   },
   "responseTime": 281,
   "statusCode": 500,
   "statusReason": "Internal Server Error",
   "text": "System.InvalidOperationException: Getperson Web Service method name is not valid.\n   at System.Web.Services.Protocols.HttpServerProtocol.Initialize()\n   at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)\n   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)",
   "totalTime": 313,
   "warnings": [
   ]
}

这里有什么问题?

4

1 回答 1

1

当您的 XML 在第一个 <?xml.....> 元素之前包含一些字符时,解析器通常会抛出“prolog 中不允许内容”错误。

这里有两个选项:

  1. 尝试将 returnedContentType 更改为“plain”,这样返回的 XML 将不会被解析,您可以看到究竟是什么导致了问题
  2. 尝试手动设置调用选项的返回内容编码属性
于 2013-06-13T04:20:48.713 回答