2010-09-08 4 views
2

Может ли кто-нибудь сказать мне, что я могу сделать, чтобы исправить эту ошибку, когда я вызываю службу WCF SOAP из JQuery?Сообщение с действием '' не может быть обработано

Ошибка:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">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).</faultstring></s:Fault></s:Body></s:Envelope> 

Если я использовать Fiddler, чтобы восстановить запрос и добавить часть заголовка SOAPAction HTTP, я получаю ту же ошибку, за исключением со значением я дал его.

Вот мой web.config:

<configuration> 
<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
</system.web> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="soapBinding"> 
       <security mode="None"> 
       </security> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    <services> 
     <service name="CatalogService" behaviorConfiguration="defaultBehavior"> 
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="soapBinding" contract="ICatalogService"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name="defaultBehavior"> 
       <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
       <serviceMetadata httpGetEnabled="true"/> 
       <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
       <serviceDebug includeExceptionDetailInFaults="false"/> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 

Вот мои App_Code/CatalogService.cs:

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] public class CatalogService : ICatalogService { 
public string HelloWorld(string name){ 
    return String.Format("Hello {0}", name);}} 

Вот мой App_Code/CatalogIService.cs:

[ServiceContract(Namespace = "http://miami.edu/")] public interface ICatalogService { 
[WebInvoke(Method = "POST", 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      ResponseFormat = WebMessageFormat.Xml, 
      RequestFormat = WebMessageFormat.Xml)] 
string HelloWorld(string name);} 

JQuery код клиента:

$.ajax({ 
type: 'POST', 
url: 'http://localhost/csw/service.svc/soap', 
data: request, 
contentType: 'text/xml; charset=utf-8', 
dataType: 'text', 
success: function (result) { 
    console.log(result); 

    $("#result").text(result); 
    //result.responseXML 
    //result.responseText 
}, 
error: function (message) { 
    console.log(message); 
    alert("error has occured" + message); 
}}); 

Вот мой запрос SOAP:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <HelloWorld xmlns="http://cstars.miami.edu/CatalogService"> <name>CarlosK</name> </HelloWorld> </s:Body> </s:Envelope> 

ответ

3

Вы отсутствуют OperationContract атрибут вашего метода HelloWorld. Чем вызов от Fiddler должен работать с SOAPAction http://miami.edu/ICatalogService/HelloWorld Если он все еще не работает, вы можете явно определить Action и ReplyAction в атрибуте OperationContract.

К вашему jQuery проблеме. Я просто проверяю функцию $ .ajax в jQuery в книге действий, и я думаю, вам нужно определить функцию для создания заголовка SOAPAction и назначить эту функцию beforeSend в $ .ajax.

Edit:

Основываясь на этом вопросе и ваш предыдущий вопрос: Почему вы хотите использовать SOAP? Похоже, вы сами разрабатываете сервис и клиент. У вас есть специальное требование использовать SOAP или это только некоторые упражнения? Гораздо проще использовать службу RESTful из jQuery. Служба RESTful может возвращать POX (простой старый XML) или JSON.

+0

Отличное спасибо. Чтобы ответить на ваш вопрос, да, я бы хотел использовать REST, но у вас есть конкретные требования к профилю приложения OGC для привязки http, требующие от меня использования SOAP. – capdragon

Смежные вопросы