2011-10-19 57 views
3

我有一個WCF休息服務。我使用4.0 rest服務應用程序創建它,所以它是無SVC的。服務器和客戶端之間不匹配

我有這樣的服務合同:

[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 
public class Service1 
{ 


    [WebGet(UriTemplate = "/Login/?username={username}&password={password}", ResponseFormat= WebMessageFormat.Json)] 
    public Response Login(string username, string password) 
    { 

     Response res; 
     BillboardsDataContext db = new BillboardsDataContext(); 
     var q = from lgin in db.logins 
       where lgin.username == username && lgin.password == password 
       select lgin; 
     if (q.Count() != 0) 
     { 
      res = new Response(true, "Login successful"); 
      return res; 
     } 
     else 
     { 
      res = new Response(false, "Login failed!"); 
      return res; 
     } 


    } 

    [WebInvoke(UriTemplate = "", Method = "POST")] 
    public void Upload(Stream fileStream) 
    { 
     FileStream targetStream = null; 
     string uploadFolder = @"C:\inetpub\wwwroot\Upload\test.jpg"; 
     using (targetStream = new FileStream(uploadFolder, FileMode.Create, 
      FileAccess.Write, FileShare.None)) 
     { 
      const int bufferLen = 65000; 
      byte[] buffer = new byte[bufferLen]; 
      int count = 0; 
      while ((count = fileStream.Read(buffer, 0, bufferLen)) > 0) 
      { 
       targetStream.Write(buffer, 0, count); 
      } 
      targetStream.Close(); 
      fileStream.Close(); 
     } 
    } 

} 

這web.config文件:

<services> 
    <service name="BillboardServices.Service1" behaviorConfiguration="Meta"> 
    <endpoint name="restful" address="" binding="webHttpBinding" behaviorConfiguration="REST" contract="BillboardServices.Service1" /> 
    <endpoint name="streamFile" address="/Upload" binding="basicHttpBinding" bindingConfiguration="streamBinding" contract="BillboardServices.Service1" /> 
    </service> 
</services> 
<behaviors> 
    <endpointBehaviors> 
    <behavior name="REST"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="Meta"> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceMetadata httpGetEnabled="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<bindings> 
    <basicHttpBinding> 
    <binding name="streamBinding" maxReceivedMessageSize="64000" maxBufferSize="64000" transferMode="Streamed" messageEncoding="Mtom"> 
     <readerQuotas maxDepth="64000" maxStringContentLength="64000" maxArrayLength="64000" maxBytesPerRead="64000" maxNameTableCharCount="64000"/> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

登錄服務工作得很好,但我有上傳操作的問題。我把它經由http://www.myhost.com/Upload一個Android應用程序,我得到這個錯誤:

Content Type multipart/form-data; boundary=wjtUI0EFrpQhBPtGne9le5_-yMxPZ_sxZJUrFf- was sent to a service expecting multipart/related; type="application/xop+xml". The client and service bindings may be mismatched. 

我無法找到此錯誤信息。有人看過這個嗎?

謝謝!

回答

1

所以事實證明,我需要使用webHttpBinding兩個端點,而不僅僅是登錄。

相關問題