2011-10-19 10 views
3

WCF 휴식 서비스가 있습니다. 4.0 rest service 응용 프로그램을 사용하여 만들었으므로 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를 통해 안드로이드 응용 프로그램을 통해 그것을 호출이 오류 얻을 :이 오류에 대한 정보를 찾을 수 없습니다

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을 사용해야한다는 것이 밝혀졌습니다.

관련 문제