我有一个通过 wsHTTPBinding 和 basicHTTPBinding 公开的 wcf webservice。后者将其端点地址指定为“/basic”,如下所示:
<endpoint address="/basic" binding="basicHttpBinding" bindingConfiguration="theAwesomeBasicHttpServerBinding" contract="LOServices.Proxy.ServiceContracts.ILOService">
<identity>
<servicePrincipalName value="HTTP/MY_MACHINE_NAME" />
</identity>
</endpoint>
绑定定义如下:
<basicHttpBinding>
<binding name="theAwesomeBasicHttpServerBinding" maxReceivedMessageSize="5000000">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
我正在尝试使用 jquery 调用其中一种网络方法。因为这是通过 basicHTTPBinding 而不是 RESTful,因此,我不会使用 JSON。因此,我正在通过 wcf 测试客户端对服务进行的先前(成功)调用构建请求 XML:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ILOService/GetLoanActions</Action>
</s:Header>
<s:Body>
<GetLoanActions xmlns="http://tempuri.org/">
<request xmlns:d4p1="http://schemas.datacontract.org/2004/07/LOServices.Proxy.Requests" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:AssociationNumber>3</d4p1:AssociationNumber>
<d4p1:IgnoreWarnings>false</d4p1:IgnoreWarnings>
</request>
</GetLoanActions>
</s:Body>
</s:Envelope>
因此,我使用的实际 javascript 的结构如下:
function callWs() {
var theRequest = " \
<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"> \
<s:Header> \
<Action s:mustUnderstand=\"1\" xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://tempuri.org/ILOService/GetLoanActions</Action> \
</s:Header> \
<s:Body> \
<GetLoanActions xmlns=\"http://tempuri.org/\"> \
<request xmlns:d4p1=\"http://schemas.datacontract.org/2004/07/LOServices.Proxy.Requests\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"> \
<d4p1:AssociationNumber>3</d4p1:AssociationNumber> \
<d4p1:IgnoreWarnings>false</d4p1:IgnoreWarnings> \
</request> \
</GetLoanActions> \
</s:Body> \
</s:Envelope>";
$.ajax({
type: "POST",
url: "http://localhost/LOServices/Services/LOService.svc/basic",
data: theRequest,
timeout: 10000,
contentType: "text/xml",
dataType: "xml",
async: false
});
}
但是,当我以这种方式运行 wcf 服务时,很不幸地收到了来自 wcf 服务的“错误请求”,这并没有让我有太多的后续工作。
我一直在努力尝试完成这项工作至少 3 个小时,所以如果有人有想法,请随时提出一些建议。
谢谢。