2011-05-05 47 views
0

我想從使用jQuery的wcf web服務獲取數據。 我的jQuery代碼如下:構建wsdl的soap請求和jQuery的服務契約

    jQuery.ajax({ 
        type: "POST", 
        url: serviceWebPath, 
        data: data, 
        contentType: "text/xml; charset=utf-8", 
        dataType: "json", 
        success: function (data) { alert (data); }, 
        error: _errorHandler 
        }); 

我有一個服務合同:

[OperationContract] 
String GetContainerByName(String _label); 

[OperationContract] 
String GetContainerByToken(Guid _Token); 

[OperationContract] 
void SetContainer(Guid securityToken, String _Content); 

我有,我可以在HTTP訪問XSD文件://.svc/mex和包括

<wsdl:operation name="GetContainerByToken"> 
    <soap:operation soapAction="http://tempuri.org/IProxyShareContextContract/GetContainerByToken" style="document" /> 
<wsdl:input> 
    <soap:body use="literal" /> 
    </wsdl:input> 
<wsdl:output> 
    <soap:body use="literal" /> 
    </wsdl:output> 
    </wsdl:operation> 

我傳遞給jQuery的數據是:

var data = '<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><GetContainerByToken><label>' + clientTokenSecuritySManager + '</label></GetContainerByToken></soap:Body></soap:Envelope>'; 

我需要訪問GetContainerByToken方法。但我繼續得到這個錯誤:

"The message with Action '' cannot be processed at the receiver, 
due to a ContractFilter mismatch at the EndpointDispatcher. This 
may be because of either a contract mismatch (mismatched Actions 
between sender and receiver) or a binding/security mismatch between 
the sender and the receiver. Check that sender and receiver have 
the same contract and the same binding (including security requirements, 
e.g. Message, Transport, None)." 

回答

1

你想從Javascript中談談SOAP?這是保守的。

這不是一個真正的答案,但嘗試使用wireshark和/或soapUI檢查您的流量。如果你有一個可用的SOAP客戶端,運行它並查看它的功能,然後嘗試複製它。

請注意,某些SOAP服務器將使用HTTP標頭來路由操作(SOAPAction)。錯誤消息讓我懷疑這可能是問題所在?

+0

好吧,我在頭文件中添加了「SOAPAction:GetContainerByToken」,現在錯誤消息是完全一樣的,除了引號現在說'GetContainerByToken'。儘管前進了一步。謝謝! – 2011-05-05 10:57:43

+0

好吧,事實證明,正確的標題不只是GetContainerByToken,但http://tempuri.org/IProxyShareContextContract/GetContainerByToken我現在可以得到一個迴應!很酷,謝謝! – 2011-05-05 12:58:50

+0

soapUI提示很棒,順便說一句! – 2011-05-13 14:04:34

2

查看Simplest SOAP example 查看完整示例。

你需要做的是找出你要瞄準的目標。 SOAPAction,名稱空間,元素名稱和順序,屬性以及所有內容。

在試圖製作重現Javascript的必要Javascript之前,很高興看到有效的工作SOAP消息的示例。

+0

雖然真正的答案是下面的答案,但這個讓我在這個方向看起來更難。感謝您的鏈接! – 2011-05-05 12:59:49

0

我相信你必須嘗試使用​​WebHTTPBinding,因爲你正在嘗試一個基於REST的客戶端。

嘗試尋找基於REST的實現,它最適合從Javascript調用。