Javascript Web服务从SOAP请求中获取空数组,而不是带字符串的数组
我有这样一种情况:我通过Ajax发送带有字符串数组的SOAP请求,请求被成功地传递到web服务,但是取消序列化的数组是空的 我拥有ASP.Net Web服务,合同如下:Javascript Web服务从SOAP请求中获取空数组,而不是带字符串的数组,javascript,c#,ajax,web-services,soap,Javascript,C#,Ajax,Web Services,Soap,我有这样一种情况:我通过Ajax发送带有字符串数组的SOAP请求,请求被成功地传递到web服务,但是取消序列化的数组是空的 我拥有ASP.Net Web服务,合同如下: [WebService(Namespace = "http://someCompany.com/WebServices/TCWS/Agent")] public class AgentService : WebService 使用以下API: [WebMethod(Description = "my action desc
[WebService(Namespace = "http://someCompany.com/WebServices/TCWS/Agent")]
public class AgentService : WebService
使用以下API:
[WebMethod(Description = "my action description", MessageName = "MyAction")]
public Result MyAction(string[] items)
我使用以下代码通过AJAX Javascript执行请求:
AgentService.prototype.DoSoapAjax = function (methodName, data, successHandler, errorHandler, state) {
// Need to use local variable so ajax request will be able to process the guid variable
var currGuid = window.AgentGUID;
var response = $.ajax({
type: "POST",
contentType: "text/xml; charset=utf-8",
methodName: methodName,
url: this.AgentServiceUrl,
data: data,
async: this.Async,
beforeSend: function (req, methodName) {
var soapActionURI = "http://someCompany.com/WebServices/TCWS/Agent/" + this.methodName;
req.setRequestHeader("SOAPAction", soapActionURI);
req.setRequestHeader("AgentGUID", currGuid);
},
success: function (xml, textStatus) {
if (successHandler != null) {
var response = xml.lastChild.firstChild.firstChild.firstChild;
successHandler(state, $.xml2json(response), textStatus);
}
},
error: function (xmlHttpRequest, textStatus, errorThrown) { if (errorHandler != null) errorHandler(state, xmlHttpRequest, textStatus, errorThrown); }
});
if (!this.Async) {
var syncResponse = new Object();
syncResponse.response = response;
syncResponse.json = $.xml2json(response.responseText);
return syncResponse;
}
return response;
};
这就是我如何计算DoSoapAjax的:
AgentService.prototype.MyAction= function (items, successHandler, errorHandler, state) {
var items = "<items arrayType='string[]'><item xsi:type='string'>first text</items><item xsi:type='string'>second text</items></items>"
var methodName = "MyAction ";
var soapXml = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body>"
soapXml += "<" + methodName + " xmlns='http://someCompany.com/WebServices/TCWS/Agent'>";
soapXml += items;
soapXml += "</" + methodName + "></soap:Body></soap:Envelope>";
var response = this.DoSoapAjax("MyAction", soapXml, successHandler, errorHandler, state);
return response;
};
SOAP请求如下所示:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<MyAction xmlns='http://someCompany.com/WebServices/TCWS/Agent'>
<items xsi:type='string'>first text</items>
<items xsi:type='string'>second text</items>
</MyAction>
</soap:Body>
</soap:Envelope>
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<MyAction xmlns='http://someCompany.com/WebServices/TCWS/Agent'>
<items>
<string>first text</string>
<string>second text</string>
</items>
</MyAction>
</soap:Body>
</soap:Envelope>
当我调试web服务时,我可以看到我使用的是MyAction方法,但是items是一个空数组,而不是带有2个字符串的数组
我的SOAP请求有问题吗?数据对象不是作为字符串数组传递的,而是作为单个字符串参数添加到正文中。正确的SOAP应该如下所示:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<MyAction xmlns='http://CosmoCom.com/WebServices/TCWS/Agent'>
<items arrayType="string[]">
<item xsi:type='string'>first text</items>
<item xsi:type='string'>second text</items>
</items>
</MyAction>
</soap:Body>
</soap:Envelope>
我已经找到了一些解决方案,但是我不明白为什么它能工作,因为我找不到任何关于它的文档。 我已将SOAP请求更改为以下内容:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<MyAction xmlns='http://someCompany.com/WebServices/TCWS/Agent'>
<items xsi:type='string'>first text</items>
<items xsi:type='string'>second text</items>
</MyAction>
</soap:Body>
</soap:Envelope>
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<MyAction xmlns='http://someCompany.com/WebServices/TCWS/Agent'>
<items>
<string>first text</string>
<string>second text</string>
</items>
</MyAction>
</soap:Body>
</soap:Envelope>
是否有人可以发布一个关于这个的解释或文档,以便更清楚?看起来,当我传递一个元素时,我输入了它的名称,当它是数组时,我输入了它的类型。我在一些小的谷歌文档中找到了这个解决方案。。。
谢谢大家在我看来,您传递的是多个字符串参数,而不是一个stringsHow数组。您在调用DoSoapAjax吗?你能发那个密码吗?@lc。添加了dosoapajax的调用者函数。尽管尝试过,但仍然不起作用。我收到了错误的请求400 SOAP请求现在看起来是什么样子?SOAP请求看起来与您上面提到的完全一样我想我找到了一个解决方案,但我真的不明白为什么它能工作,因为我还没有找到类似的文档。也许你对此很熟悉。我很快会把我的答案贴出来