2013-08-27 103 views
0

我正嘗試從我的應用調用一個簡單的WCF服務,但我總是收到錯誤400的錯誤請求。從加速器調用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(); 
} 

Service1.cs

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

網絡。 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> 

這是服務跟蹤查看的結果:

<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> 

有人能幫助我嗎?我嘗試了一切,但沒有任何工作! :(

回答

0

嘗試

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"; 
+0

同樣的錯誤。我也嘗試:IService1.cs文件中的'UriTemplate =「HelloWorld」' –

相關問題