Ошибка 400 Неверный запрос при вызове службы WCF из appcelerator

Я пытаюсь вызвать простую службу WCF из своего приложения, но всегда получаю ошибку 400 неверного запроса.

Это мой код в appcelerator:

var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(1200);

xhr.onerror = function(e) {
    if (xhr.status != 200) {
        alert("The service is currently unavailable. Please Try Again Later. \nStatus:" + xhr.status + ". "+ xhr.statusText);
        return;
    }
};

xhr.onload = function() {
    var response = JSON.parse(this.responseText);
};

var request_url = "http://192.168.1.130/wcfTestPubb/wcfTest.Service1.svc/HelloWorld";
xhr.setRequestHeader("enctype", "multipart/form-data");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.open("GET", request_url);
xhr.send();

и это мой WCF:

IService1.cs

public interface IService1 {
    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "HelloWorld/", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
    string HelloWorld();
}

Сервис1.cs

public class Service1 : IService1 {
    public string HelloWorld()
    {
        return "HELLO WORLD!";
    }     
}

Web.config

<?xml version="1.0"?>
    <configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="wcfTest.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http:///Design_Time_Addresses/wcfTest/Service1/"/>
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="wcfTest.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>    </configuration>

Это результат Service Trace Viewer:

<TraceData>
    <DataItem>
        <TraceRecord Severity="Information" Channel="Analytic" xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord">
            <TraceIdentifier>http://msdn.microsoft.com/it-IT/library/System.ServiceModel.Diagnostics.TraceHandledException.aspx</TraceIdentifier>
            <Description>Throwing an exception. Exception details: System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---> System.Xml.XmlException: The body of the message cannot be read because it is empty. --- End of inner exception stack trace ---   in System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result)   in System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result)   in System.Runtime.AsyncResult.SyncContinue(IAsyncResult result)   in System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state)   in System.ServiceModel.Channels.HttpChannelListener`1.HttpContextReceivedAsyncResult`1.ProcessHttpContextAsync()</Description>
            <AppDomain>/LM/W3SVC/1/ROOT/wcfTestPubb-11-130221681396205807</AppDomain>
            <Exception>
                <ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
                <Message>There is a problem with the XML that was received from the network. See inner exception for more details.</Message>
                <StackTrace>[...]</StackTrace>
                <ExceptionString>System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---> System.Xml.XmlException: The body of the message cannot be read because it is empty. --- End of inner exception stack trace ---   in System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result)   in System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result)   in System.Runtime.AsyncResult.SyncContinue(IAsyncResult result)   in System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state)   in System.ServiceModel.Channels.HttpChannelListener`1.HttpContextReceivedAsyncResult`1.ProcessHttpContextAsync()</ExceptionString>
                <InnerException>
                    <Exception>
                        <ExceptionType>System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
                        <Message>The body of the message cannot be read because it is empty.</Message>
                        <StackTrace>[...]</StackTrace>
                        <ExceptionString>System.Xml.XmlException: The body of the message cannot be read because it is empty.</ExceptionString>
                    </Exception>
                </InnerException>
            </Exception>
        </TraceRecord>
    </DataItem>
</TraceData>

Кто-нибудь может мне помочь? Я пробовал все, но ничего не работает! :(


person Marco Boemo    schedule 27.08.2013    source источник


Ответы (2)


Пытаться

var request_url = "http://192.168.1.130/wcfTestPubb/wcfTest.Service1.svc/HelloWorld/";

вместо

var request_url = "http://192.168.1.130/wcfTestPubb/wcfTest.Service1.svc/HelloWorld";
person belhassine    schedule 28.08.2013
comment
Та же ошибка. Я также пытаюсь использовать: UriTemplate = "HelloWorld" в файле IService1.cs - person Marco Boemo; 28.08.2013

удалите эту часть из IService1.cs, а затем проверьте:

BodyStyle = WebMessageBodyStyle.WrappedRequest

или использовать

BodyStyle = WebMessageBodyStyle.Bare

вы проверили это с скрипачом? проверьте здесь: http://pantestmb.blogspot.com/search/label/POST и здесь: http://www.mehdi-khalili.com/fiddler-in-action/part-1

person user2684131    schedule 30.08.2013