在worklight中调用webservice错误

时间:2013-06-13 03:00:37

标签: web-services ibm-mobilefirst worklight-adapters

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

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

我还要在本教程中使用我的worklight应用程序link调用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": [
   ]
}

这里有什么问题?

1 个答案:

答案 0 :(得分:1)

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

这里有两个选项:

  1. 尝试将returnedContentType更改为“plain”,这样就不会解析返回的XML,您可以看到究竟可能导致问题的原因
  2. 尝试手动设置调用选项的returnedContentEncoding属性