У меня есть веб-сервис asmx, который возвращает список стран для континента.При использовании JQuery для вызова веб-службы я использую:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "InternationalLookup.asmx/LoadCountries",
data: '{ continentName: "' + $(this).val() + '" }',
dataType: "json",
success: function (response) {
//..code
},
error: function (response) {
//..code
}
});
Это прекрасно работает с кодом asmx, но при использовании службы WCF я должен изменить его на:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "InternationalLookup.svc/LoadCountries",
**data: '{ \"continentName\": "' + $(this).val() + '" }',**
dataType: "json",
success: function (response) {
//..code
},
error: function (response) {
//..code
}
});
Обратите внимание на разницу в данных, которые я должен передать, теперь требуются дополнительные кавычки вокруг имени континента.Мой сервис WCF и его конфигурация:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="InternationalLookupBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="InternationalLookup">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="InternationalLookupBehavior"
name="USQ.Websites.RefreshLayout.Webservices.UsqInternationalLookup">
<endpoint address="" binding="wsHttpBinding" contract="IInternationalLookup">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
[ServiceContract]
public interface IInternationalLookup
{
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string LoadCountries(string continentName);
}
Несмотря на то, что у него возникли некоторые проблемы, я хотел бы знать, почему параметр для веб-сервиса WCF долженбыть завернутым в дополнительные кавычки.